node.jsreactjswindowsnpmnext.js

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


I have a Next.js application that works and then when I leave it and come back to it I get

  errno: -4048,
  code: 'EPERM',
  syscall: 'rmdir',
  path: 'C:\\Users\\gmacr\\Google Drive\\Optical-Font-Website\\O\\.next\\server\\pages'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opt@0.1.0 dev: `next dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the opt@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\gmacr\AppData\Roaming\npm-cache\_logs\2021-10-16T21_14_26_886Z-debug.log 

I tried using npm clean cache. using Windows 10. When I create a new Next app and copy my working files over the program runs without error until I leave it for a while and come back to it...


Solution

  • It happens to me when the project directory is inside "Google Drive"!!

    All you have to do is delete the ".next" directory.

    Or add a script to package.json to delete it (windows 10 tested):

     "scripts": {
        "dev": "(if exist .next rd /s /q .next 2>nul) && next dev",
    },