Skip to content

Unable to run npm run build due to Error: ENOENT: no such file or directory #45159

Description

@sgrobert

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

next info

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103
    Binaries:
      Node: 16.17.1
      npm: 9.2.0
      Yarn: 1.22.19
      pnpm: 7.22.0
    Relevant packages:
      next: 13.1.4
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

package.json

  • "@next/font": "^13.1.4",
  • "next": "^13.1.5-canary.2",

next.config.js

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  experimental: {
    appDir: true,
  },
  staticPageGenerationTimeout: 1000,
}

module.exports = nextConfig

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://stackblitz.com/edit/vercel-next-js-ubvjrc?file=app%2Flayout.jsx,next.config.js

To Reproduce

  1. Run npm install
  2. Run npm run build

Sample Execution In StackBlitz:

Screenshot 2023-01-23 at 7 49 24 AM

Describe the Bug

While attempting to run the command npm run build, the following error message pops up:

...

info  - Creating an optimized production build  
info  - Compiled successfully
info  - Linting and checking validity of types  
info  - Collecting page data  
info  - Generating static pages (24/24)

> Build error occurred
[Error: ENOENT: no such file or directory, rename '/Users/.../.next/export/404.html' -> '/Users/.../.next/server/pages/404.html'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: '/Users/.../.next/export/404.html',
  dest: '/Users/.../.next/server/pages/404.html'
}
info  - Finalizing page optimization .%      

END OF `npm run build`.


I tried the following multiple solutions in an attempt to resolve the issue, but the error still occurs:
[1] Moved Affected Files Out To Temp Folder /app-backup Instead of Keeping Under /app

  • (a) Moved /app/(error-pages)/404/page.jsx to /app-backup/404/page.jsx
  • (b) Error is thrown for the next file instead for /app/(error-pages)/500/page.jsx
  • (c) The same thing happened when I attempted to move the same file for /app/(error-pages)/500/page.jsx
  • (d) The same issue repeats for other files when [1c] was moved.

[2] Reinstalled Node Packages

[3] Added staticPageGenerationTimeout To next.config.js

[4] Attempted Alternative Solutions via NextJS's Issues Docs

[5] Updated NextJs to the Latest Canary Version

  • (a) Updated from "next": "^13.1.4" to "next": "^13.1.5-canary.2"
  • (b) Ran thru [2a] -> [2c]. Same results

Expected Behavior

The npm run build process should complete as per normal, especially when all relevant bugs are fixed, which will signal to me that the build will run safely on a server-execution.

Which browser are you using? (if relevant)

Brave Version 1.47.171 Chromium: 109.0.5414.87 (Official Build) (arm64)

How are you deploying your application? (if relevant)

Localhost Only, running npm run build, which executes next build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.please add a complete reproductionPlease add a complete reproduction.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions