serverless / serverless-plugin-typescript

Serverless plugin for zero-config Typescript support
MIT License
783 stars 223 forks source link

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

Closed Benzer1406 closed 1 year ago

Benzer1406 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

uhinze commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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

mdrijwan commented 2 years ago

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

joaogameprog commented 2 years ago

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/

harrisgeo88 commented 2 years ago

As per https://github.com/serverless/serverless-plugin-typescript/issues/170#issuecomment-513518997 I tried the following

rm -rf .serverless
rm -rf node_modules
npm i

Then serverless deploy started working again 🎉

mtrojanowski commented 2 years ago

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 commented 2 years ago

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