2017-09-26 42 views
1

我已经越来越几个错误与此类似:UnhandledPromiseRejectionWarning:不清楚哪个文件或行警告是

(node:30892) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): SyntaxError 

从这些问题(What is Unhandled Promise RejectionNodeJS UnhandledPromiseRejectionWarning)看来,这些警告是由尚未造成然后

然而,这些警告没有问题所在的文件或行号。有什么方法可以找到它/缩小范围吗?

回答

0

你可以捕获unhandled promise rejection warning,并使用给定的数据知道它发生的地方。

process.on('unhandledRejection', (reason, p) => { 
    console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); 
}); 

这gyus here告诉我们:

enter image description here

+0

此打印出 “的console.log SRC \软件\ app.jsx:9 unhandledRejection”,其中9号线是位置process.on中的console.log,而不是实际警告的位置。记录错误而不是error.message会产生无益的踪迹。有任何想法吗? – user7470360

+1

我得到这个错误: 的console.log的src \软件\ app.jsx:9 未处理的排斥反应:承诺的原因:SyntaxError错误 在XMLHttpRequest.open( \ node_modules \ jsdom \ LIB \ jsdom \住\ xmlhttprequest.js: 486:15) 在dispatchXhrRequest( \ node_modules \ Axios公司\ lib中\适配器\ xhr.js:45:13) 在xhrAdapter( \ node_modules \ Axios公司\ lib中\适配器\ xhr.js:12:10) 在dispatchRequest( \ node_modules \ axios \ lib \ core \ dispatchRequest.js:52:10) at process._tickCallback(internal/process/next_tick.js:109:7) 这是错误的实际来源吗? – user7470360

+0

公平Idk。我从来没有使用它,但它似乎是正确的答案看着github的答案。 –