解決方法
檢查hosts
文件, 應該是localhost
沒了
添加
127.0.0.1 localhost
起因
想要翻譯文檔, 打算使用 docusaurus
根據文檔執行
npx create-docusaurus@latest my-website classic
后創建項目成功, 安裝依賴一切正常
當我執行 start 時遇到錯誤
yarn run v1.22.17
$ docusaurus start
[INFO] Starting the development server...
[SUCCESS] Docusaurus website is running at http://localhost:3000/.
● Client █████████████████████████ setup (3%)
watch run
(node:40311) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
/Users/sftc/Desktop/my-website/node_modules/webpack-dev-server/lib/Server.js:2440
throw error;
^
Error: getaddrinfo ENOTFOUND localhost
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'localhost'
}
error Command failed with exit code 1.
我們應該會下意識看到第一句Warning
把它當成報錯, 實際上這個不會影響運行
饒了好大一圈, 看到了這個回答 Cant load a react app after starting server
It's just a deprecation warning from one of the libraries you used within the app, have you tried to open http://localhost:3000 on your local? it is supposed to be running fine
我當然是看項目沒跑起來才搜索報錯原因的啊
我開始懷疑node版本問題, 懷疑人生
這就是拿着半截就跑...
終於仔細檢查發現
Error: getaddrinfo ENOTFOUND localhost
這才是罪魁禍首, 原來是公司的VPN修改了hosts
文件, 把localhost
干掉了