C/C++教程

docusaurus 启动出错 - Error: getaddrinfo ENOTFOUND localhost

本文主要是介绍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干掉了

这篇关于docusaurus 启动出错 - Error: getaddrinfo ENOTFOUND localhost的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!