Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden error with await rejected promise inside getStaticPaths #32180

Closed
urffin opened this issue Dec 6, 2021 · 7 comments
Closed

Hidden error with await rejected promise inside getStaticPaths #32180

urffin opened this issue Dec 6, 2021 · 7 comments

Comments

@urffin
Copy link

urffin commented Dec 6, 2021

What 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');
};
@urffin urffin added the bug Issue was opened via the bug report template. label Dec 6, 2021
@urffin urffin changed the title Hidden error with await promise inside getStaticPaths Hidden error with await rejected promise inside getStaticPaths Dec 6, 2021
@balazsorban44
Copy link
Member

balazsorban44 commented Dec 6, 2021

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:

if (isError(err) && err.message !== 'INVALID_DEFAULT_EXPORT')

@urffin
Copy link
Author

urffin commented Dec 6, 2021

Hmmmm. interesting... But anyway this seems not an obviously: we have exception, but can't take reason and error message related to page without a React Component

@urffin
Copy link
Author

urffin commented Dec 6, 2021

@balazsorban44 is it possibly do more relevant error message? without changing nested promise

as workaround, of course i can

await promise.catch(e => Promise.reject(new Error(e)))

but this looks ugly

@balazsorban44
Copy link
Member

await promise in that case would be enough I think. If the promise fails, it will just throw its error, which is caught by Next.js

@urffin
Copy link
Author

urffin commented Dec 7, 2021

await promise in that case would be enough I think. If the promise fails, it will just throw its error, which is caught by Next.js

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.

@balazsorban44 balazsorban44 added area: Application Code and removed bug Issue was opened via the bug report template. labels Dec 7, 2021
@ijjk
Copy link
Member

ijjk commented Feb 1, 2022

Hi, this should be fixed in the latest version of Next.js v12.0.10, please update and give it a try.

Related fix: #33753

@ijjk ijjk closed this as completed Feb 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants