next build command fails with some inner error
See original GitHub issueBug report
Describe the bug
$ next build
throws an error at optimization step:
Automatically optimizing pages...
> Build error occurred
[Error: ENOENT: no such file or directory, rename '/Users/username/Projects/projectname/.next/export/blog.html' ->
'/Users/username/Projects/projectname/.next/serverless/pages/blog.html'] {
errno: -2,
code: 'ENOENT',
syscall: 'rename',
path: '/Users/username/Projects/projectname/.next/export/blog.html',
dest: '/Users/username/Projects/projectname/.next/serverless/pages/blog.html'
}
for pages/blog/index.js
file with the following getStaticProps
export async function getStaticProps() {
let url = "/blog"
let knex = await import("knex/client").then(m => m.default)
let page = await knex("page")
.select("title", "seoTitle", "body")
.filter({url})
.firstRequired()
return {
props: {page, ogType: "website"},
}
}
It looks like some bug in NextJS build pipeline to me.
It started with recent NextJS and Now updates though I can’t tell the particular breaking update at this moment. Can it be related to Now CLI 19.0.0? I dunno how to downgrade this tool to an earlier version.
Extra info:
- It doesn’t happen with
getServerSideProps
or with purely static pages. - It doesn’t happen with
$ next dev
.
To Reproduce
I can make a sandbox if necessary.
Expected behavior
next build
should work 🤷
System information
- OSX
- Browser (if applies) [e.g. chrome, safari]
- Version of Next.js: tried with 9.3.5, 9.3.6, 9.3.7
- Version of Now: tried with 19.0.0, 19.0.1
- Version of Node.js: 12.16.3
Notes
Besides trying different NextJS versions I tried rm -rn node_modules
and yarn cache clean
.
No effect on the bug.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:19 (6 by maintainers)
Top Results From Across the Web
`next build` and `npm run build` fail with different errors, but ...
I currently have a Next.js website that I want to run next build on. However, when I run next build , I get:...
Read more >Next.js build is failing - Render community
My Nextjs build keeps failing, although it works fine locally. My error logging shows the following: Jun 22 05:07:47 PM > Build error...
Read more >Failed: an internal error occurred - Cloudflare Pages
I am trying to setup my nextjs application for the first time. I am keep getting “Failed: an internal error occurred”.
Read more >Build Failed - Web App - Build issue - AppGyver forums
Nothing had changed since the last build except I replaced some images. ... “FAILED with ERROR: │ [ error ] [build] COMMAND: npx...
Read more >Command failed with exit code 1: npm run build - Netlify fix 2020
Udemy Courses:- 9 React Projects on Udemy - https://bit.ly/2D83M8c- 9 React Projects on Gumroad ...
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
Also running into this issue:
In
getStaticPaths
, I filter out index.Update
The error is not a NextJS bug but rather a special case for which reporting can be improved.
I handle the same object at
pages/blog/index.js
as a blog page and, at the same time atpages/[...slugs].js
as a generic page.pages/[...slugs].js
Which causes the above conflict. I’ll leave it up to you guys how to treat such cases. IMO they should be recognized and reported in some clear way.