由于UnhandledPromiseRejectionWarning无法打开本地主机:错误:退出,代码3

时间:2019-03-14 12:21:40

标签: javascript node.js angular xdgutils

尝试为“ my-app”重新安装node_modules,问题仍然存在,而opn / index.js错误:代码3退出。现在xdg-open具有执行权限

[root@localhost my-app]# ng serve --open
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

Date: 2019-03-14T13:15:55.316Z
Hash: bde8066a5f0c0f28e4f3
Time: 7824ms
chunk {es2015-polyfills} es2015-polyfills.js, es2015-polyfills.js.map (es2015-polyfills) 284 kB [initial] [rendered]
chunk {main} main.js, main.js.map (main) 11.5 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 236 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 16.3 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.76 MB [initial] [rendered]
ℹ 「wdm」: Compiled successfully.
(node:49888) UnhandledPromiseRejectionWarning: Error: Exited with code 3
    at ChildProcess.cp.once.code (/var/www/html/my-app/node_modules/opn/index.js:84:13)
    at Object.onceWrapper (events.js:277:13)
    at ChildProcess.emit (events.js:189:13)
    at maybeClose (internal/child_process.js:970:16)
    at Socket.stream.socket.on (internal/child_process.js:389:11)
    at Socket.emit (events.js:189:13)
    at Pipe._handle.close (net.js:597:12)
(node:49888) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:49888) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^C
[root@localhost my-app]#

预先感谢您的帮助

1 个答案:

答案 0 :(得分:0)

首先检查您的捕获或错误功能。

这是一个例子

new Promise((_, reject) => reject(new Error('woops'))).
  catch(error => { console.log('caught', err.message); });

它将给出此错误

$ node test.js
(node:9825) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): ReferenceError: err is not defined
(node:9825) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这就是为什么未处理的拒绝如此阴险的原因。您可能认为自己捕获了一个错误,但是错误处理程序可能导致了另一个错误。如果在.catch()函数中返回一个promise,也会遇到类似的问题。

我建议您看看这个link