大前端与勇士

打工人带你一起刷大前端副本 111

docusaurus 启动出错 - Error: getaddrinfo ENOTFOUND localhost

解决方法

检查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干掉了

posted on 2021-12-25 02:35  秦伟杰  阅读(947)  评论(0编辑  收藏  举报

导航