question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

next build command fails with some inner error

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
nummicommented, May 22, 2020

Also running into this issue:

/pages/[uid].js
/pages/index.js

In getStaticPaths, I filter out index.

const pages = await ...

const paths = pages.results
  .filter((page) => {
    return page.uid !== 'index'
  })
  .map((page) => ({
    params: { uid: page.uid },
  }))

return {
  paths,
  fallback: true,
}
5reactions
ivan-kleshnincommented, May 11, 2020

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 at pages/[...slugs].js as a generic page.

pages/[...slugs].js

export async function getStaticPaths() {
  return {
    paths: [... "/blog" ...] // among other things!
    fallback: true,
  }
}  

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found