當(dāng)我使用此命令建立新的 Nuxt 3 專案時(shí):
npx nuxi init nuxt-app
它輸出此錯(cuò)誤:
ERROR (node:1752) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time 09:53:25 (Use `node --trace-warnings ...` to show where the warning was created) ERROR Failed to download template from registry: fetch failed 09:53:25 at /C:/Users/myname/AppData/Local/npm-cache/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13269:11 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async downloadTemplate (/C:/Users/myname/AppData/Local/npm-cache/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13268:20) at async Object.invoke (/C:/Users/myname/AppData/Local/npm-cache/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/chunks/init.mjs:13336:15) at async _main (/C:/Users/myname/AppData/Local/npm-cache/_npx/a95e0f536cf9a537/node_modules/nuxi/dist/cli.mjs:50:20)
我的環(huán)境:
起初我懷疑這是由於我的網(wǎng)路造成的。但是當(dāng)我嘗試安裝其他 npm 套件時(shí)沒(méi)有收到錯(cuò)誤。
我也遇到了同樣的錯(cuò)誤(Windows 10)。我的很簡(jiǎn)單。
ERROR Error: Failed to download template from registry: fetch failed
是的,這與網(wǎng)路或IP被封鎖有關(guān)。不過(guò)我還是設(shè)法解決了。這就是我所做的。
先進(jìn)入C:\Windows\System32\drivers\etc
#在此資料夾中尋找「hosts」檔案。用記事本以管理員身份開(kāi)啟?,F(xiàn)在在文件末尾(以及其他 IP 位址)添加此行。
// Some other ip address 185.199.108.133 raw.githubusercontent.com
這應(yīng)該可以解決問(wèn)題。
我在這裡找到了原因。
確實(shí)是網(wǎng)路問(wèn)題。它無(wú)法從命令列存取 raw.githubusercontent.com
,因?yàn)樗也坏较鄳?yīng)的 IP 位址。
將 raw.githubusercontent.com
的正確 IP 位址新增至 Windows 主機(jī)檔案後,問(wèn)題已修正