npm run dev报错,events.js:160 throw er; // Unhandled 'error' event

问题描述:

用vue-cli脚手架搭建项目,执行 npm run dev 报错

现象:

[email protected] dev C:\Users\Administrator.AT10173\Desktop\pro
node build/dev-server.js
Starting dev server...
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8080
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at Server._listen2 (net.js:1258:14)
at listen (net.js:1294:10)
at Server.listen (net.js:1390:5)
at EventEmitter.listen (C:\Users\Administrator.AT10173\Desktop\pro\node_modules\express\lib\application.js:618:24)
at Object. (C:\Users\Administrator.AT10173\Desktop\pro\build\dev-server.js:83:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run"
"dev"
npm ERR! node v6.11.2
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: node build/dev-server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'node build/dev-server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the pro package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node build/dev-server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs pro
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls pro
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Administrator.AT10173\Desktop\pro\npm-debug.log

解决办法

在项目中config的文件夹中,修改index.js的端口号,修改成你想要的端口号,有时搭建的项目多的话,容易造成端口号的占用。

最好的使用方法:

运行vue项目(执行npm run dev)命令,使用docs窗口打开,而使用git命令,使用node软件。这样就不会出现上面的问题,放置端口被占用。

你可能感兴趣的:(npm run dev报错,events.js:160 throw er; // Unhandled 'error' event)