Skip to content

EPERM: operation not permitted, unlink '.../.build/node_modules' #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Benzer1406 opened this issue Nov 5, 2020 · 10 comments · Fixed by #282
Closed

EPERM: operation not permitted, unlink '.../.build/node_modules' #219

Benzer1406 opened this issue Nov 5, 2020 · 10 comments · Fixed by #282

Comments

@Benzer1406
Copy link

Hi,

I can't run serverless deploy --verbosewithout getting the following issue:

Error: EPERM: operation not permitted, unlink '.../.build/node_modules'
      at Object.unlinkSync (fs.js:951:3)
      at TypeScriptPlugin.<anonymous> (.../node_modules/serverless-plugin-typescript/src/index.ts:195:12)
      at Generator.next (<anonymous>)
      at .../node_modules/serverless-plugin-typescript/dist/src/index.js:7:71
      at new Promise (<anonymous>)
      at __awaiter (.../node_modules/serverless-plugin-typescript/dist/src/index.js:3:12)
      at TypeScriptPlugin.copyDependencies (.../node_modules/serverless-plugin-typescript/dist/src/index.js:166:16)
      at TypeScriptPlugin.<anonymous> (.../node_modules/serverless-plugin-typescript/src/index.ts:45:20)
      at Generator.next (<anonymous>)
      at fulfilled (.../node_modules/serverless-plugin-typescript/dist/src/index.js:4:58)
      at process._tickCallback (internal/process/next_tick.js:68:7)

The compilation of typescript seems to work as I get the message Serverless: Typescript compiled..

I can invoke all functions locally and they work without any issue. It's just the deploy that doesn't work.

I ran npm install, closed all terminals including VSCode and reopened it. Same issue.
I cleaned the cache of npm but didn't help either.

My versions:
npm 6.14.8
Your Environment Information --------------------------- Operating System: darwin Node Version: 10.15.3 Framework Version: 2.8.0 Plugin Version: 4.1.1 SDK Version: 2.3.2 Components Version: 3.2.4

serverless-plugin-typescript: "^1.1.9"

Any idea?

@Benzer1406
Copy link
Author

Just found another issue related to that: #170 which proposes downgrading the plugin to 1.1.7. I ended up removing the plugin and it worked again.

@craPkit
Copy link

craPkit commented Jan 29, 2021

This error is sometimes reproducible by cancelling the deployment script (sls deploy). Deleting the build folder helps, occasionally.

@uhinze
Copy link

uhinze commented Jul 4, 2021

Had the same issue. It's caused by a straightforward bug in the code (unlinkSync being used on the entire .build/node_modules directory, but can only be used on a single file).
Now the question is why the .build/node_modules dir is there at all, and this depends I would say. In @craPkit case it was probably left over from a previous build, in which case it helps to delete before running the script.
In my case, it was because I had custom includes for packaging (txt and html files), so in a previous step the plugin also copies the txt and html files from any node_modules over. After removing the custom includes, it works again.

@molavec
Copy link

molavec commented Aug 25, 2021

Just found another issue related to that: #170 which proposes downgrading the plugin to 1.1.7. I ended up removing the plugin and it worked again.

It works for me! Thanks. Keep this issue until new update please that works, please.

@hckhanh
Copy link

hckhanh commented Sep 11, 2021

Is there any news for this issue? Until now, it's 2.0 already but it seems this issue has not been resolved.

@mdrijwan
Copy link

the issue still exists, ridiculous! downgraded the plugin to 1.1.7 and only then it works

@joaogameprog
Copy link

It seems that the fs.unlinkSync() should be used to remove only files, NOT folders.
To remove a directory needs to use
fs.rmdirSync(outModulesPath, {recursive: true, force: true})

[node_modules\serverless-plugin-typescript\dist\src\index.js line:181
Plugin version: 2.1.0]
image

"The fs.unlinkSync() method is used to synchronously remove a file or symbolic link from the filesystem. This function does not work on directories, therefore it is recommended to use fs.rmdir() to remove a directory."
https://www.geeksforgeeks.org/node-js-fs-unlinksync-method/

joaogameprog pushed a commit to joaogameprog/serverless-plugin-typescript that referenced this issue Jan 7, 2022
… remove node_modules when packaging serverless project
@harrisgeo88
Copy link

harrisgeo88 commented Jan 9, 2022

As per #170 (comment) I tried the following

rm -rf .serverless
rm -rf node_modules
npm i

Then serverless deploy started working again 🎉

@mtrojanowski
Copy link

Had the same issue. It's caused by a straightforward bug in the code (unlinkSync being used on the entire .build/node_modules directory, but can only be used on a single file). Now the question is why the .build/node_modules dir is there at all, and this depends I would say. In @craPkit case it was probably left over from a previous build, in which case it helps to delete before running the script. In my case, it was because I had custom includes for packaging (txt and html files), so in a previous step the plugin also copies the txt and html files from any node_modules over. After removing the custom includes, it works again.

That was my issue also. I added custom includes in serverless.yml through the package.patterns configuration. That caused the issue with unlinkSync. Fortunately, in my case, I could just remove the includes as it turned out they're not needed.

@drewbrend
Copy link

I also ran into this issue with the latest version.

In addition to this:

rm -rf .serverless
rm -rf node_modules
npm i

I also had to: rm -rf .build

Then I was able to serverless package and serverless deploy

douwe-rm added a commit to douwe-rm/serverless-plugin-typescript that referenced this issue Oct 5, 2022
douwe-rm added a commit to douwe-rm/serverless-plugin-typescript that referenced this issue Oct 5, 2022
@douwe-rm douwe-rm mentioned this issue Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants