当我运行npm run dev时,错误背后的原因是什么?

时间:2018-10-05 14:16:51

标签: node.js laravel vue.js

我正在使用Vuejs运行Laravel应用程序,并且正在运行npm run dev,并且遇到以下错误。

events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES 0.0.0.0:80
    at Server.setupListenHandle [as _listen2] (net.js:1269:19)
    at listenInCluster (net.js:1334:12)
    at Server.listen (net.js:1421:7)
    at Function.listen (/var/www/frontend/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/var/www/frontend/build/dev-server.js:60:22)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
Emitted 'error' event at:
    at emitErrorNT (net.js:1313:8)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@1.0.0 dev: `node build/dev-server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend@1.0.0 dev 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!     /home/ubuntu/.npm/_logs/2018-10-05T13_47_28_825Z-debug.log

这是我的错误日志。

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'dev' ]
2 info using npm@6.4.1
3 info using node@v10.10.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle frontend@1.0.0~predev: frontend@1.0.0
6 info lifecycle frontend@1.0.0~dev: frontend@1.0.0
7 verbose lifecycle frontend@1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle frontend@1.0.0~dev: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/var/www/frontend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
9 verbose lifecycle frontend@1.0.0~dev: CWD: /var/www/frontend
10 silly lifecycle frontend@1.0.0~dev: Args: [ '-c', 'node build/dev-server.js' ]
11 silly lifecycle frontend@1.0.0~dev: Returned: code: 1  signal: null
12 info lifecycle frontend@1.0.0~dev: Failed to exec dev script
13 verbose stack Error: frontend@1.0.0 dev: `node build/dev-server.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
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:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid frontend@1.0.0
15 verbose cwd /var/www/frontend
16 verbose Linux 3.13.0-100-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev"
18 verbose node v10.10.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error frontend@1.0.0 dev: `node build/dev-server.js`
22 error Exit status 1
23 error Failed at the frontend@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

由于我是Node js术语的新手,所以我无法理解该错误并解决它,你们可以帮助我解决此错误吗?任何帮助将不胜感激。

非常感谢。

1 个答案:

答案 0 :(得分:0)

没有root特权就无法运行侦听1024以下端口的进程。您是使用sudo还是类似的方法来确保您具有正确的权限?

您可以使用sudo运行命令或设置反向代理。反向代理可用于在另一个端口上启动服务,以将呼叫从该端口转发到新设置的端口。

在这里反向代理是更可靠,更安全的选择,但是可以使用sudo。