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

Returning notFound from getStaticProps causes an error during next export #24422

Open
fracture91 opened this issue Apr 24, 2021 · 1 comment · May be fixed by #24481
Open

Returning notFound from getStaticProps causes an error during next export #24422

fracture91 opened this issue Apr 24, 2021 · 1 comment · May be fixed by #24481

Comments

@fracture91
Copy link

@fracture91 fracture91 commented Apr 24, 2021

What version of Next.js are you using?

10.1.3, 10.1.4-canary.16

What version of Node.js are you using?

14.15.3

What browser are you using?

Firefox 89.0b3

What operating system are you using?

Ubuntu 18.04.5 LTS

How are you deploying your application?

next export

Describe the Bug

If a page returns { notFound: true } from getStaticProps, then running next build && next export will result in an error like the following:

> next-notfound-ssg-bug@0.1.0 export /home/ahurle/Documents/Programming/next-notfound-ssg-bug
> next export

info  - Using webpack 4. Reason: future.webpack5 option not enabled https://nextjs.org/docs/messages/webpack5
info  - using build directory: /home/ahurle/Documents/Programming/next-notfound-ssg-bug/.next
info  - Copying "static build" directory
info  - No "exportPathMap" found in "next.config.js". Generating map from "./pages"
info  - Launching 7 workers
info  - Copying "public" directory
info  - Exporting (3/3)
[Error: ENOENT: no such file or directory, copyfile '/home/ahurle/Documents/Programming/next-notfound-ssg-bug/.next/server/pages/blog/post.html' -> '/home/ahurle/Documents/Programming/next-notfound-ssg-bug/out/blog/post.html'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'copyfile',
  path: '/home/ahurle/Documents/Programming/next-notfound-ssg-bug/.next/server/pages/blog/post.html',
  dest: '/home/ahurle/Documents/Programming/next-notfound-ssg-bug/out/blog/post.html'
}

It seems like next export expects an html file to be present, but there isn't one.

Expected Behavior

No error message, next export finishes successfully, and visiting /blog/post in production results in a 404 just like when I use next build && next start locally

To Reproduce

You can find a minimal reproduction with instructions in the readme here: https://github.com/fracture91/next-notfound-ssg-bug There's also a canary branch showing the issue still exists in 10.1.4-canary.16

For a little context, my use case is I want to be able to see unpublished blog posts in dev mode, but production builds should exclude them and result in a 404. Here is my "real" code where I hit the problem, plus a hacky workaround.

Another potential workaround is to avoid using next export in my Vercel deploy, since my example repo seems to work fine with next build alone.

These comments look like the same problem: #19578 (comment) #20355

@erosenberg
Copy link

@erosenberg erosenberg commented Jun 4, 2021

Experiencing the exact same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants