docusaurus startup error-Error: getaddrinfo ENOTFOUND localhost

created at 12-28-2021 views: 42

solution

Check the hosts file, it should be localhost is gone

Add:

127.0.0.1 localhost

cause

Want to translate documents, plan to use docusaurus

According to the documentation

npx create-docusaurus@latest my-website classic

After the project is created successfully, everything is normal for the installation dependency

I get an error when I execute 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.

We should subconsciously see the first sentence of Warning as an error, in fact this will not affect the operation

After a long time, I saw this answer 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

Of course, I searched for the cause of the error after seeing the project did not run.

I began to doubt the node version problem, doubt life

This is just half of the run...

I finally checked carefully and found

Error: getaddrinfo ENOTFOUND localhost

This is the culprit. It turned out that the company's VPN modified the hosts file and killed localhost.

created at:12-28-2021
edited at: 12-28-2021: