javascript - Uncaught (in promise) error occurs in the build environment
大家讲道理
大家讲道理 2017-05-16 13:28:00
0
2
577

Such an error will not occur in local development, but such an error will occur after npm run build is sent to the server

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
滿天的星座

Are you using axios to send http requests? If yes

axios.get().then().catch()

Remember to add the last one.catch()

为情所困

The final reason why the Uncaught (in promise) error occurs is: "One of your promises did not add a catch statement"
Try to check where the writing is not perfect.
The following content is excerpted from my blog "Promise User Manual"


We all know that Promise.reject returns a Promise object in a rejected state. For such a Promise object, if there is no onRejected callback declared in its subsequent then | catch, it will throw an "Uncaught (in promise) ..." Error.

As shown in the picture above, the original statement is "Promise.reject('Return a Promise with rejection status');" It is not followed by any then|catch statement, so it will throw an error, and the external Promise cannot Capture.
Not only that, Promises are clearly differentiated. Any errors thrown by the internal Promise cannot be perceived and captured by the external Promise object. At the same time, because the promise is asynchronous, the try catch statement cannot capture its errors.
Therefore Develop good habits and remember to write catch on your promise.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template