cli icon indicating copy to clipboard operation
cli copied to clipboard

nuxi always using default npm registry

Open wdyyy opened this issue 1 year ago • 7 comments

Environment

Nuxt project info: 9:52:35 PM


  • Operating System: Linux
  • Node Version: v20.12.2
  • Nuxt Version: 3.12.4
  • CLI Version: 3.12.0
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devServer, devtools, modules
  • Runtime Modules: @nuxt/[email protected], [email protected]
  • Build Modules: -

Reproduction

Only in the region where users couldn't access https://registry.npmjs.org, like china, you can reproduce it.

Describe the bug

No matter what registry I set, when I run npx nuxi@latest module add XXX, nuxi report errors like this:

ERROR  [GET] "https://registry.npmjs.org/@nuxt/ui/latest": <no response> fetch failed                                                                                         9:43:28 PM

  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async $fetchRaw2 (/home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/shared/nuxi.ec1423ac.mjs:267:14)
  at async $fetch2 (/home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/shared/nuxi.ec1423ac.mjs:304:15)
  at async resolveModule (/home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/chunks/add2.mjs:26359:15)
  at async Object.setup (/home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/chunks/add2.mjs:26219:15)
  at async runCommand$1 (/home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/shared/nuxi.6aad497e.mjs:1620:5)
  at async runCommand$1 (/home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/shared/nuxi.6aad497e.mjs:1639:11)
  at async runCommand$1 (/home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/shared/nuxi.6aad497e.mjs:1639:11)
  at async runMain$1 (/home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/shared/nuxi.6aad497e.mjs:1777:7) 

I found that this error was lies in /home/wdy/.npm/_npx/b95349761371180e/node_modules/nuxi/dist/chunks/add2.mjs:26359:15, which is:

const pkg = await $fetch(
    `https://registry.npmjs.org/${pkgName}/${pkgVersion}`
  );

I change the URL here to my current NPM registry, and the problem solved.

Additional context

Should the URL for fetch be changed to the current npm registry rather that https://registry.npmmirror.com ?

Logs

No response

wdyyy avatar Jul 24 '24 13:07 wdyyy

I meet the same trouble, too. And it seems nuxi will not use the proxy set in system env. For adding a module though, you can just search and download directly from npm repo, then add the module info to the nuxt.config.ts, it works the same effect.

Kiameow avatar Jul 25 '24 08:07 Kiameow

Thanks for reporting, I think we could catch the error here:

  • https://github.com/nuxt/cli/blob/bca75ab6490dfc444e3b6766ba5c47572622e2d3/src/commands/module/add.ts#L219-L221
  • https://github.com/nuxt/cli/blob/bca75ab6490dfc444e3b6766ba5c47572622e2d3/src/utils/update.ts#L11-L13

If the error is a fetch failed, fallback to call the proxy.

Happy to open a PR?

atinux avatar Jul 31 '24 10:07 atinux

I think directly using the user-defined proxy would be better if there is proxy env, cause the waiting time is kind of torture, and this is the default action of many tools and software.

Kiameow avatar Jul 31 '24 15:07 Kiameow

I see, what could be the proxy env variable?

atinux avatar Aug 12 '24 13:08 atinux

normally it would be http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY

Kiameow avatar Aug 12 '24 13:08 Kiameow

Happy to open a PR to support HTTPS_PROXY @Kiameow ?

atinux avatar Aug 21 '24 10:08 atinux

Happy to open a PR to support HTTPS_PROXY @Kiameow ?

PR submitted, but it's about registry support. I find adding mirror registry support way more easy than adding proxy support to reach the similar effect, $fetch in nuxt cli seems not supporting proxy. Introducing another fetch lib or agents stuff is kind of overdoing?

Kiameow avatar Sep 14 '24 02:09 Kiameow

I think we can close this issue as it's about the npm registry, but we should certainly support proxy environment variable if possible 🙏

we can track in https://github.com/nuxt/cli/issues/419

danielroe avatar Oct 22 '24 13:10 danielroe