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

support http proxy when using nuxi init with node >= 18 #159

Closed
ikexing-cn opened this issue Oct 5, 2022 · 69 comments
Closed

support http proxy when using nuxi init with node >= 18 #159

ikexing-cn opened this issue Oct 5, 2022 · 69 comments
Assignees
Labels
bug Something isn't working

Comments

@ikexing-cn
Copy link

ikexing-cn commented Oct 5, 2022

Environment


  • Operating System: Darwin
  • Node Version: v16.17.0
  • Nuxt Version: 0.0.0
  • Nitro Version: -
  • Package Manager: unknown
  • Builder: webpack
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Not exist

Describe the bug

 ERROR  Failed to download template from registry: request to https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json failed, reason: connect ECON3

  at /Users/xdclass/.npm/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13269:11
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
  at async downloadTemplate (/Users/xdclass/.npm/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13268:20)
  at async Object.invoke (/Users/xdclass/.npm/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13336:15)
  at async _main (/Users/xdclass/.npm/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/cli.mjs:50:20)

Additional context

curl https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json

{
  "name": "v3",
  "defaultDir": "nuxt-app",
  "url": "https://v3.nuxtjs.org",
  "tar": "https://codeload.github.com/nuxt/starter/tar.gz/refs/heads/v3"
}

Everything works fine when I request the URL directly, I think this might be a bug in nuxt.

Logs

No response

Copy link
Member

What happens when you run:

node -e "require('https').get('https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json')"

@ikexing-cn
Copy link
Author

node -e "require('https').get('https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json')"

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 0.0.0.0:443
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16)
Emitted 'error' event on ClientRequest instance at:
    at TLSSocket.socketErrorListener (node:_http_client:481:9)
    at TLSSocket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '0.0.0.0',
  port: 443
}

It looks like the same error is reported...

@danielroe
Copy link
Member

It seems there is something stopping your node from connecting. Maybe an application firewall?

@ikexing-cn
Copy link
Author

That's strange, my application firewall is always off...... any other possible reasons?

@danielroe
Copy link
Member

Are you using a proxy?

Would you run:

env | grep -i proxy
npm config list | grep -i proxy

@ikexing-cn
Copy link
Author

ikexing-cn commented Oct 5, 2022

Yes, I using proxy on clash.

env | grep -i proxy

all_proxy=sock5://127.0.0.1:8889
http_proxy=http://127.0.0.1:8889
https_proxy=http://127.0.0.1:8889
ALL_PROXY=sock5://127.0.0.1:8889

And then npm config list | grep -i proxy has not output.

Copy link
Member

So the issue is that HTTPS is not working over your HTTP proxy: lovell/sharp#679.

We will need to implement a similar fix.

@danielroe danielroe added bug Something isn't working and removed bug Something isn't working labels Oct 5, 2022 — with Volta.net
@so1ve
Copy link

so1ve commented Oct 6, 2022

In fact, it is difficult to access Github and Raw in China, and we often use proxies. However, nuxi seems to be the same as degit, the default tar mode does not use the set proxy.

@danielroe danielroe changed the title Error when I using npx nuxi init nuxt-app. support http proxy when using nuxi init Oct 17, 2022
@codingcn
Copy link

codingcn commented Nov 3, 2022

In china, I succeeded

Just set DNS 114.114.114.114

@yonhung
Copy link

yonhung commented Nov 3, 2022

I got the same error.
It worked for me after I added raw.githubusercontent.com Ip address to my Windows hosts file.
It seems a firewall dns cache pollution problem.

@so1ve
Copy link

so1ve commented Nov 3, 2022

Does degit use https_proxy and https_proxy?

@pi0
Copy link
Member

pi0 commented Nov 3, 2022

Created issue for giget (used by nuxi cli). PR welcome.

unjs/giget#23

@danielroe danielroe added the good first issue Good for newcomers label Nov 3, 2022 — with Volta.net
@pi0
Copy link
Member

pi0 commented Nov 18, 2022

Landed by unjs/giget#24

@pi0 pi0 closed this as completed Nov 18, 2022
@codername-123
Copy link

I'm still having this issue on my windows machine

@danielroe
Copy link
Member

@codername-123 Would you try using npx nuxi@latest in case your npm is caching an old version?

@codername-123
Copy link

My bad @danielroe it was a problem with my ISP... As soon as I changed my ISP it started working properly

Copy link
Member

Glad everything is resolved 😊

@GeorgeHcc
Copy link

in china ,I'm failed

@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@CharryMoon
Copy link

get ip of raw.githubusercontent.com from a web.
and set these into hosts file (windows: C:\Windows\System32\drivers\etc)
185.199.111.133 raw.githubusercontent.com
rerun 'npx nuxi init nut3-app', and it works

@pi0
Copy link
Member

pi0 commented Mar 6, 2023

Reopening to investigate more.

@CNMathon
Copy link

CNMathon commented Oct 6, 2023

@danielroe So, has it really been solved? I still have this problem, and this issue has been open for more than one year.

@pi0
Copy link
Member

pi0 commented Oct 6, 2023

The main issue is native fetch API provided by newer Node.js versions (18+), does not support HTTP agents for proxy support. I am looking for a solution for this. (older issue reports are however unrelavant. this issue contains multiple reports for different causes)

@sumasagrp
Copy link

sumasagrp commented Oct 17, 2023

when i do a curl to https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json it works

however when i do

node -e "require('https').get('https://raw.githubusercontent.com/nuxt/starter/templates/templates/v3.json')"

it does not work

AggregateError at internalConnectMultiple (node:net:1114:18) at internalConnectMultiple (node:net:1177:5) at Timeout.internalConnectMultipleTimeout (node:net:1687:3) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) Emitted 'error' event on ClientRequest instance at: at TLSSocket.socketErrorListener (node:_http_client:495:9) at TLSSocket.emit (node:events:514:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'ETIMEDOUT', [errors]: [ Error: connect ETIMEDOUT 185.199.109.133:443 at createConnectionError (node:net:1634:14) at Timeout.internalConnectMultipleTimeout (node:net:1685:38) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { errno: -110, code: 'ETIMEDOUT', syscall: 'connect', address: '185.199.109.133', port: 443 }, Error: connect ENETUNREACH 2606:50c0:8003::154:443 - Local (:::0) at internalConnectMultiple (node:net:1176:40) at Timeout.internalConnectMultipleTimeout (node:net:1687:3) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { errno: -101, code: 'ENETUNREACH', syscall: 'connect', address: '2606:50c0:8003::154', port: 443 }, Error: connect ETIMEDOUT 185.199.108.133:443 at createConnectionError (node:net:1634:14) at Timeout.internalConnectMultipleTimeout (node:net:1685:38) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { errno: -110, code: 'ETIMEDOUT', syscall: 'connect', address: '185.199.108.133', port: 443 }, Error: connect ENETUNREACH 2606:50c0:8002::154:443 - Local (:::0) at internalConnectMultiple (node:net:1176:40) at Timeout.internalConnectMultipleTimeout (node:net:1687:3) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { errno: -101, code: 'ENETUNREACH', syscall: 'connect', address: '2606:50c0:8002::154', port: 443 }, Error: connect ETIMEDOUT 185.199.110.133:443 at createConnectionError (node:net:1634:14) at Timeout.internalConnectMultipleTimeout (node:net:1685:38) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { errno: -110, code: 'ETIMEDOUT', syscall: 'connect', address: '185.199.110.133', port: 443 }, Error: connect ENETUNREACH 2606:50c0:8001::154:443 - Local (:::0) at internalConnectMultiple (node:net:1176:40) at Timeout.internalConnectMultipleTimeout (node:net:1687:3) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { errno: -101, code: 'ENETUNREACH', syscall: 'connect', address: '2606:50c0:8001::154', port: 443 }, Error: connect ETIMEDOUT 185.199.111.133:443 at createConnectionError (node:net:1634:14) at Timeout.internalConnectMultipleTimeout (node:net:1685:38) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { errno: -110, code: 'ETIMEDOUT', syscall: 'connect', address: '185.199.111.133', port: 443 }, Error: connect ENETUNREACH 2606:50c0:8000::154:443 - Local (:::0) at internalConnectMultiple (node:net:1176:40) at Timeout.internalConnectMultipleTimeout (node:net:1687:3) at listOnTimeout (node:internal/timers:575:11) at process.processTimers (node:internal/timers:514:7) { errno: -101, code: 'ENETUNREACH', syscall: 'connect', address: '2606:50c0:8000::154', port: 443 } ] }

Seems

Node.js does not use HTTP_PROXY environment variables. See this discussion nodejs/node#8381.

To set a global Node.js proxy use https://github.com/gajus/global-agent.

I think this is the culprit

Possible work around ?? nodejs/undici#1650 (comment)
I can't belive there is no proxy support in 2023 .... working in corporate environment becomes a nightmare

@pi0
Copy link
Member

pi0 commented Oct 17, 2023

Fully agree with you @sumasagrp sadly this is a limitation with Node/undici that lacks built-in HTTP_PROXY support whereas it is a well-known standard... (also little bit of corporate firewalls that consider "github" as possible harmful resource and block it most of the times)

Sorry for delay on this. this is still on my todo list to find best workaround. Possibly (also) in lowset level (ofetch) to make proxy support for most of our ecosystem out of the box.

@subinznz
Copy link

subinznz commented Oct 17, 2023

Bun seems to have support for http_proxy. thanks for all your hard work

@liamwang
Copy link

@codingcn Thanks. 114's DNS works for me.

BTW, Aliyun's DNS doesn't work, don't try.

@lzb-libra
Copy link

I have the same issue. Besides the usual settings like changing DNS, modifying the hosts file, and using VPN, I've tried everything, but it still doesn't work.

@caodaiquang
Copy link

I have same issue :(

@lzb-libra
Copy link

I have same issue :(

The best way is actually to give up using it altogether, why hang oneself on one tree? I've already given up.

@pi0
Copy link
Member

pi0 commented Dec 14, 2023

Hi all again and sorry for delay on it. I understand for those behind a firewall, it must be a really hard experience and for that, I apologize (I guess on behalf of the lazy Node.js team too haha) it is not supported yet 🙏🏼

I will try to jump at at as soon as possible.

@so1ve
Copy link

so1ve commented Dec 14, 2023

As a Chinese user, I know the seriousness of this bug, but I don't think it is the right behavior to express one's negative emotions in issues. At the same time, Nuxt is an open source project. Thanks to the Nuxt team for their hard work over the past few years.

@hzgotb
Copy link

hzgotb commented Dec 20, 2023

有梯子的方案:

Powershell:

# 请根据实际情况设置梯子地址
$env:all_proxy="ip:port"
$env:FORCE_NODE_FETCH=1
# 最后执行初始化,请根据实际情况执行
pnpm dlx nuxi@latest init my-app

Bash

# 同上,请根据实际情况设置梯子地址和初始化命令
export all_proxy="ip:port" && export FORCE_NODE_FETCH=1 && pnpm dlx nuxi@latest init my-app

心路历程:

翻了翻相关的仓库,在 unjs/giget#120 中看到了解决方法

然后捋了一下整个链路
nuxi.init -> giget.downloadTemplate -> giget.download -> giget.sendFetch -> node-fetch-native.fetch

没有细看 node-fetch-native 的代码,只是稍微看了一下文档,应该是逐渐使用node原生实现的fetch来替代之前的node-fetch方案,并且对不支持原生fetch的旧node版本进行了Polyfill (猜的)。所以在有梯子的情况下还是不生效(貌似原生fetch不接受代理)。
而之前的node-fetch会通过梯子的,那么如上引用的issue所言,通过FORCE_NODE_FETCH来切换到可以用梯子的fetch去下载模板

没梯子的方案:
cli的init.ts代码是这样的

template = await downloadTemplate(templateName, {
        dir: ctx.args.dir,
        cwd,
        force: Boolean(ctx.args.force),
        offline: Boolean(ctx.args.offline),
        preferOffline: Boolean(ctx.args.preferOffline),
        registry: process.env.NUXI_INIT_REGISTRY || DEFAULT_REGISTRY,
      })

可以通过设置环境变量来更改模板地址
Powershell

$env:NUXI_INIT_REGISTRY="https://gitee.com/hzgotb/nuxt-starter/raw/templates/templates"
pnpm dlx nuxi@latest init my-app

@pi0
Copy link
Member

pi0 commented Dec 24, 2023

Hi. HTTP proxy support for Node.js versions with native fetch added to the latest build of nuxi CLI (read more)

If you want to early test, you can try with nuxi-nightly channel:

http_proxy=http://localhost:9080 npx nuxi-nightly@latest init nuxt-app

(port 9080 is for Tor, you can replace it with your own!)

@pi0 pi0 changed the title support http proxy when using nuxi init support http proxy when using nuxi init with node >= 18 Dec 24, 2023
@pi0 pi0 removed the good first issue Good for newcomers label Dec 24, 2023
@chunten
Copy link

chunten commented Feb 2, 2024

我有同样的问题。除了更改DNS、修改hosts文件、使用VPN等常用设置外,我已经尝试了一切,但仍然不起作用。

me too

@pi0
Copy link
Member

pi0 commented Feb 14, 2024

With latest nuxi, http proxy should be supported out of the box!

@pi0 pi0 closed this as completed Feb 14, 2024
@ricky52529
Copy link

get ip of raw.githubusercontent.com from a web. and set these into hosts file (windows: C:\Windows\System32\drivers\etc) 185.199.111.133 raw.githubusercontent.com rerun 'npx nuxi init nut3-app', and it works

it works~ thank you~

@Milchreis
Copy link

Hi,

the nightly-build works for init. Thank you for the hint, but on module add I got the same issue. Could you add the proxy-support for module, too?

@pi0
Copy link
Member

pi0 commented May 27, 2024

@Milchreis ~> #419 (this will add proxy support to all internal fetches happening with nuxi CLI)

(however package managers should still also respect and support http_proxy)

@ClungTsang
Copy link

In china, I succeeded

Just set DNS 114.114.114.114

it did work ,appreciate

@Hetari
Copy link

Hetari commented Oct 10, 2024

Guide: Resolving nuxi init Error: "Failed to download template from registry" on Linux

Steps to Resolve:

  1. Find the IP Address for raw.githubusercontent.com:

    • Go to IP Address Lookup.
    • Search for raw.githubusercontent.com.
    • Take note of the current IP address. As of this writing, it could be 185.199.108.133, but you should verify this for the most up-to-date address.
  2. Edit the /etc/hosts File:

    • Open your terminal.
    • Use the following command to open the /etc/hosts file in a text editor with root privileges:
      sudo nano /etc/hosts
    • Add a new entry for raw.githubusercontent.com with the IP address you found. Example:
      185.199.108.133 raw.githubusercontent.com
      
    • Save the file and exit the editor (Ctrl + O to save, Ctrl + X to exit).
  3. Test the Fix:

    • Try running the nuxi init command again:
      npx nuxi@latest init my-app
    • It should now successfully download the required template.
      Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests