1、报错内容
Error: getaddrinfo ENOTFOUND localhost
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
Emitted 'error' event on Server instance at:
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1500:12)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:17) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'localhost'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2、解决方法:
(1)尝试更改版本,nvm use 14.17.0,更改后 还是报错
(2)打开config文件夹下的index.js文件找到如下图这段代码:
javascript
host: 'localhost', // can be overwritten by process.env.HOST ipv6配置'[::1]'
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
host 修改为 127.0.0.1