Hidden error with await rejected promise inside getStaticPaths
See original GitHub issueWhat version of Next.js are you using?
12.0.0
What version of Node.js are you using?
14.16.0, 15.9.0
What browser are you using?
any browser
What operating system are you using?
macOS
How are you deploying your application?
next build
Describe the Bug
if in async function getStaticPaths
error raised in some nested async function, called with await, like this
export const getStaticPaths = async () => {
await Promise.reject('Error hidden');
// throw new Error('Raised error');
};
then when execute next build
in console would be output just
Build optimization failed: found page without a React Component as default export in pages/dyn/[num]
instead normal error message. If throw error directly - then log is fine
Expected Behavior
output concrete error message
To Reproduce
https://stackblitz.com/edit/nextjs-pnhrbs?file=pages/dyn/[num].jsx
To reproduce run: next build
enough
export const getStaticPaths = async () => {
await Promise.reject('Error hidden'); // any rejected promise with message
// throw new Error('Raised error');
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Wait until all promises complete even if some rejected
The explicit way to to resolve this issue is to simply call .catch on the internal promises, and return the error from their...
Read more >Handling those unhandled promise rejections with JS async ...
You put your code inside an async function in order to use await calls; One of your await ed functions fails (i.e. rejects...
Read more >Handling Promise rejection with catch while using await
In this article, we will try to understand how we may handle Promise's rejection with a try/catch block while using await inside an ......
Read more >how do you resolve application error a client side exception has ...
Side note: Promise gotchas ... This code misunderstands the above asynchronous issues. Specifically, $.ajax() doesn't freeze the code while it checks the '/ ......
Read more >Data Fetching: getStaticPaths - Next.js
API reference for `getStaticPaths`. Learn how to fetch data and generate static pages with `getStaticPaths`.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, this work only if promise rejected with
new Error
, if reject reason any other value, for example string - output just message about Build optimization failed: found page without a React Component as default export in …This is a problem to detect real error reason.
It is generally a good idea to reject with an
Error
if you have control over that.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject#description
Currently, this is why you are getting that message. Next.js checks if the thrown error is an instance of
Error
: https://github.com/vercel/next.js/blob/cffd209a677db9c953c15e4fc8e168a278d3908c/packages/next/build/index.ts#L1027