2017-04-26 108 views
1

我是NodeJS和NPM的新手。「npm start」顯示「未處理的承諾拒絕」錯誤

當我一個項目的NodeJS中運行npm start,出現如下錯誤:

Starting the development server... 

(node:9417) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Exited with code 3 

這個錯誤是什麼意思? 如何調試這個問題?

$ grep start package.json 
    "start": "react-scripts start", 

$ npm -v 
3.10.10 
$ node -v 
v6.10.1 

$ npm ls react-scripts 
[email protected] /home/li/sample 
└── [email protected] 

回答

0

我猜你的代碼像下面

new Promise(function(resolve, reject){ 
    reject(0) 
}).then() 

當你運行上面的代碼,你會得到「未處理的承諾拒絕」。

with Promise/A + standard #point-21。承諾必須提供當時的方法來獲取其當前或最終的價值或原因。

你最好寫代碼如下

promise.then(onFulfilled, onRejected) 

其他方式來避免這個問題,你可以聽的unhandledRejection事件與過程

​​
+0

有沒有辦法知道這個錯誤來自?代碼中有很多'reject()'。我不確定哪一個導致錯誤。 – Xin

相關問題