Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nuxi always using default npm registry #453

Open
wdyyy opened this issue Jul 24, 2024 · 7 comments
Open

nuxi always using default npm registry #453

wdyyy opened this issue Jul 24, 2024 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers workaround available

Comments

@wdyyy
Copy link

wdyyy commented Jul 24, 2024

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

@danielroe danielroe transferred this issue from nuxt/nuxt Jul 24, 2024
@Kiameow
Copy link
Contributor

Kiameow commented Jul 25, 2024

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.

@atinux atinux added upstream and removed upstream labels Jul 31, 2024
@atinux
Copy link
Member

atinux commented Jul 31, 2024

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

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

Happy to open a PR?

@Kiameow
Copy link
Contributor

Kiameow commented Jul 31, 2024

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.

@atinux
Copy link
Member

atinux commented Aug 12, 2024

I see, what could be the proxy env variable?

@Kiameow
Copy link
Contributor

Kiameow commented Aug 12, 2024

normally it would be http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY

@atinux
Copy link
Member

atinux commented Aug 21, 2024

Happy to open a PR to support HTTPS_PROXY @Kiameow ?

@Kiameow
Copy link
Contributor

Kiameow commented Sep 14, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers workaround available
Projects
None yet
Development

No branches or pull requests

3 participants