【问题标题】:VueJS: Error: listen EADDRNOTAVAIL: address not availableVueJS:错误:监听 EADDRNOTAVAIL:地址不可用
【发布时间】:2020-07-19 14:12:20
【问题描述】:

我是 JS 新手,最近我用 Vue-CLI 2 学习了 vue.js,但是现在我想安装新版本的 Vue-CLI 4.3.0,我已经做了一步一步的教程来安装它,但是当我运行 $ npm run serve 时,它会给我这样的错误。根据类似的 StackOverflow 问题(listen EADDRNOTAVAIL error in Node.js),我猜这与 IP 地址有关,但我真的不知道如何实现它

> vue-cli-new@0.1.0 serve /Users/arul/selfLearner/Vuejs_learn/vue-cli3-tutorial/vue-cli-new
> vue-cli-service serve

 INFO  Starting development server... 11% building 13/15 modules 2 active ...vue-cli-new/node_modules/webpack-dev-server/client/utils/reloadApp.jsevents.js:292
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRNOTAVAIL: address not available 36.86.63.182:8080
    at Server.setupListenHandle [as _listen2] (net.js:1296:21)
    at listenInCluster (net.js:1361:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1498:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:71:10) Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1340:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {   code: 'EADDRNOTAVAIL',   errno: -49,   syscall: 'listen',   address: '36.86.63.182',   port: 8080 } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! vue-cli-new@0.1.0 serve: `vue-cli-service serve` npm ERR! Exit status 1 npm ERR!  npm ERR! Failed at the vue-cli-new@0.1.0 serve script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!     /Users/arul/.npm/_logs/2020-04-07T10_46_15_552Z-debug.log

这是日志文件

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/usr/local/Cellar/node/13.12.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'serve'
1 verbose cli ]
2 info using npm@6.14.4
3 info using node@v13.12.0
4 verbose run-script [ 'preserve', 'serve', 'postserve' ]
5 info lifecycle vue-cli-new@0.1.0~preserve: vue-cli-new@0.1.0
6 info lifecycle vue-cli-new@0.1.0~serve: vue-cli-new@0.1.0
7 verbose lifecycle vue-cli-new@0.1.0~serve: unsafe-perm in lifecycle true
8 verbose lifecycle vue-cli-new@0.1.0~serve: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/arul/selfLearner/Vuejs_learn/vue-cli3-tutorial/vue-cli-new/node_modules/.bin:/Users/arul/google-cloud-sdk/bin:/usr/local/bin:/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/home/username/bin:/usr/local/homebrew:/Users/arul/development/flutter/bin
9 verbose lifecycle vue-cli-new@0.1.0~serve: CWD: /Users/arul/selfLearner/Vuejs_learn/vue-cli3-tutorial/vue-cli-new
10 silly lifecycle vue-cli-new@0.1.0~serve: Args: [ '-c', 'vue-cli-service serve' ]
11 silly lifecycle vue-cli-new@0.1.0~serve: Returned: code: 1  signal: null
12 info lifecycle vue-cli-new@0.1.0~serve: Failed to exec serve script
13 verbose stack Error: vue-cli-new@0.1.0 serve: `vue-cli-service serve`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1026:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid vue-cli-new@0.1.0
15 verbose cwd /Users/arul/selfLearner/Vuejs_learn/vue-cli3-tutorial/vue-cli-new
16 verbose Darwin 19.2.0
17 verbose argv "/usr/local/Cellar/node/13.12.0/bin/node" "/usr/local/bin/npm" "run" "serve"
18 verbose node v13.12.0
19 verbose npm  v6.14.4
20 error code ELIFECYCLE

【问题讨论】:

标签: node.js vue.js npm


【解决方案1】:

EADDRNOTAVAIL 来自您计算机的网络代码,通过您的操作系统。

当它来自listen() 调用时,这意味着您尝试启动服务器(在您的情况下为 nodejs Web 服务器)来处理传入请求在不存在的 Internet 协议 (IP) 地址上。 在您的情况下,错误地址是36.86.63.182。端口 8080 是正确的。

如果您使用的是 mac 或 Linux 机器,则可以输入命令 ifconfig。它将显示有关您的网络接口的大量信息。要仅提取 Internet 协议地址,请使用此

ifconfig | grep "inet "

在 Windows 上是

ipconfig | findstr IPv4

我敢打赌,该列表中没有地址 36.86.63.182。因此,作为 Vue 教程一部分的 nodejs 服务器正在尝试侦听其他人的 IP 地址。你不能那样做™。当你尝试时,你会得到EADDRNOTAVAIL。

在这种情况下,您想要监听地址0.0.0.0,这意味着“这台机器上的所有地址”。或者,如果失败,则在地址127.0.0.1 上,这意味着这台机器的本地主机环回地址。

问题是“为什么它在错误的地址上监听?”从这里很难说。

你的vue服务器配置错误吗?寻找

如果可能的话,最简单的尝试就是重启你的机器。自从您上次启动它以来,可能已经出现了一些古怪的配置。 ???

接下来要尝试的事情是:查找一个可能名为 HOST 的环境变量,该变量设置为虚假 IP 地址。在 Mac / Linux 上

env | grep "36.86.63.182"

在 Windows 上

set | findstr "36.86.63.182"

如果你发现有问题的环境变量,你可以为当前会话删除它,说Linux / mac(给出你找到的环境变量的名称,这里我以HOST为例

unset HOST

窗户

set HOST=

那么事情应该会奏效。

至于永久摆脱伪造的环境变量,请查看或寻求帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 2019-05-26
    • 2017-10-12
    • 2021-02-11
    • 2020-11-09
    • 2020-04-08
    • 2021-02-26
    相关资源
    最近更新 更多