search

Home  >  Q&A  >  body text

javascript - Uncaught (in promise) error occurs in the build environment

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

大家讲道理大家讲道理2749 days ago560

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-05-16 13:30:00

    Are you using axios to send http requests? If yes

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

    Remember to add the last one.catch()

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:30:00

    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.

    reply
    0
  • Cancelreply