MOHAMMAD SIDDIQUE
MOHAMMAD SIDDIQUE

Reputation: 521

Next JS : Error: EPERM: operation not permitted, open

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?

Upvotes: 26

Views: 35005

Answers (12)

You got this error because you were running quite too many processes simultaneously.

Simple solution that works for me: whenever you get this error, close your VS Code and open it again.

It works all the time. Hope this helps!

Upvotes: -1

Kamrul Hasan Rafi
Kamrul Hasan Rafi

Reputation: 11

For my perspectation, I just terminated my current terminal and then reopen my project and then just commanded "npm run build" in my terminal again, Problem solved!

Upvotes: 0

mohammad khakshoor
mohammad khakshoor

Reputation: 1

you need to kill the ports that the app was running on them in the dev mode.

you can use the command : npx kill-port <port> like npx kill-port 3000

also you can combine the ports to terminated them at once like : npx kill-port 3000 3001 3002 3003

Upvotes: 0

natee
natee

Reputation: 31

This cause because your development mode is running, try to CTRL + C to close. And then start npm run build again.

Upvotes: 1

Fanta Five
Fanta Five

Reputation: 21

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.

Upvotes: 2

PolyBlend Solutions
PolyBlend Solutions

Reputation: 1

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.

Upvotes: 0

natee
natee

Reputation: 31

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

Upvotes: 2

Ashutosh Dash
Ashutosh Dash

Reputation: 654

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

Upvotes: 5

Deepak Thakur
Deepak Thakur

Reputation: 101

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.

Upvotes: 3

Steve Chambers
Steve Chambers

Reputation: 39454

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.

Upvotes: 65

Chris Plesniak
Chris Plesniak

Reputation: 109

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!

Upvotes: 5

Isaac
Isaac

Reputation: 1

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

Upvotes: 0

Related Questions