serverless-plugin-typescript
serverless-plugin-typescript copied to clipboard
EPERM: operation not permitted, unlink '.../.build/node_modules'
Hi,
I can't run serverless deploy --verbose
without 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?
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.
This error is sometimes reproducible by cancelling the deployment script (sls deploy
). Deleting the build folder helps, occasionally.
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.
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.
Is there any news for this issue? Until now, it's 2.0 already but it seems this issue has not been resolved.
the issue still exists, ridiculous! downgraded the plugin to 1.1.7
and only then it works
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]
"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/
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 🎉
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 anynode_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.
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