Next JS : Error: EPERM: operation not permitted, open
Asked Answered
H

8

17

I am trying to build the next Js app production files to deploy it on cPanel, when I execute npm run dev the app is working just fine but as I start to build a production file with the help of this video(https://youtu.be/1ykSXau838c) and executes npm run build it gives me an error in the terminal as given below:

PS C:\Users\hp\Desktop\reactJs-project\NextJs\test-app> npm run build

> [email protected] build
> next build

info  - Checking validity of types
info  - Creating an optimized production build .node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, open 'C:\Users\hp\Desktop\reactJs-project\NextJs\test-app\.next\trace'
Emitted 'error' event on WriteStream instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {    
  errno: -4048,
  code: 'EPERM',
  syscall: 'open',
  path: 'C:\\Users\\hp\\Desktop\\reactJs-project\\NextJs\\test-app\\.next\\trace'
}

so I just want to know is there any way to solve this problem?

Henchman answered 13/4, 2022 at 3:26 Comment(2)
Try this: #34601432Cacao
Are you currently running the app in dev? If yes, cancel that process and try to build it again. Most likely the build is not able to access the trace due to being open by the dev process.Lamphere
H
50

Posting comment from Koronag as an answer (as it helped me with this error and seems the most likely cause)...

This error is commonly seen when running a build while the dev server is already running.

E.g. in my case, I had a local build running via npm run dev and was trying to commit/push code, which invoked a Git Hook that also runs npm run dev.

Hemimorphite answered 18/7, 2022 at 15:47 Comment(1)
Yep. Rookie mistake, but I made it.Voluntarism
A
4

For me, it works fine this answer drives me to the resolver. I run 2 scripts in terminals:

  • once for development
  • another for the build process.

So after killing the development script it looks perfectly fine!

Anglomania answered 10/8, 2022 at 22:59 Comment(0)
P
2

In my case, npm run dev was running in another terminal. I closed that and rerun the command. It worked fine.

Preponderant answered 16/8, 2023 at 6:24 Comment(0)
K
1

Stop the server development, and try to build again. It works on me

Or if you want to force it (using Typescript) you can see on next docs right here https://nextjs.org/docs/app/api-reference/next-config-js/typescript

Kneepan answered 12/1 at 18:57 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Angell
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewCashew
R
1

this error arises, when you are running the application in local. ->like you were doing this

"npm run dev" in one terminal and in another termianl -> you were trying to build the application for some use. "npm run build" so this won't work, and this will give the above error.

to solve, stop the running application in local then run "npm run build"

thanks.

Royce answered 11/6 at 16:11 Comment(0)
R
0

From next-sitemap repo README.md

"Having next-sitemap command & next-sitemap.js file may result in file opening instead of building sitemaps in windows machines.

As a solution to this, it is now possible to use a custom config file instead of next-sitemap.js. Just pass --config .js to build command."

Next-Sitemap README.md - Building Sitemaps

The above worked for me

Ramos answered 26/5, 2022 at 13:41 Comment(0)
M
0

This also happen if your website is running on IIS. To run the dev server from terminal (code editor), stop the server on IIS and the error will go away.

Mohican answered 14/6, 2023 at 5:28 Comment(0)
G
0

I solve this error. In my case, I had a local build running via npm run dev and was trying to commit/push code, which invoked a Git Hook that also runs npm run dev.

Gregarious answered 7/6 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.