serverless-plugin-typescript icon indicating copy to clipboard operation
serverless-plugin-typescript copied to clipboard

EEXIST when invoking locally for the second time

Open SkyLeite opened this issue 5 years ago • 15 comments

Invoking a function locally with serverless invoke local -f hello works the first time, but returns the following error on subsequent runs:

EEXIST: file already exists, symlink '/home/rodrigo/Repos/upnid-api/functions/boletos/node_modules' -> '/home/rodrigo/Repos/upnid-api/functions/boletos/.build/node_modules'

Removing the .build directory makes it work again.

SkyLeite avatar Jun 19 '19 00:06 SkyLeite

I had the same issue... turns out after adding a package.json and running npm install the error is gone

Selion05 avatar Jul 04 '19 16:07 Selion05

@RodrigoLeiteF @Selion05

I had this same issue, but it seems to be resolved if I place my handlers inside a ./src folder rather than the root.

Weetbix avatar Jul 09 '19 14:07 Weetbix

Could we consider this issue resolved or do we feel that it needs more attention?

JackCuthbert avatar Jul 15 '19 00:07 JackCuthbert

I'm not sure, honestly. I haven't run into this issue after deleting the .build directory, but something causes it. We can close it if you'd prefer, I wouldn't mind reopening later if needed.

SkyLeite avatar Jul 16 '19 00:07 SkyLeite

I still get it if i have the node_modules dir in a parent directory (shared with multiple serverless services)

Selion05 avatar Jul 16 '19 08:07 Selion05

I have my node_modules symlink'd into a service directory and was getting this issue. I symlink'd my package.json and package-lock.json to that same directory and the issue subsided.

Ryanauger95 avatar Aug 17 '19 17:08 Ryanauger95

buuuut sls deploy does not work. EEXIST: file already exists, symlink '../../node_modules/' -> '.....build/node_modules'

Ryanauger95 avatar Aug 17 '19 18:08 Ryanauger95

I'm not sure this is a good answer, but here is the change I made locally to get this working:

/**
  * Attempt to symlink a given path or directory and copy if it fails with an
  * `EPERM` error.
  */
 linkOrCopy(srcPath, dstPath, type) {
     return __awaiter(this, void 0, void 0, function* () {
         return fs.symlink(srcPath, dstPath, type)
             .catch(error => {
             if (error.code === 'EPERM' && error.errno === -4048) {
                 return fs.copy(srcPath, dstPath);
             }
             /* This code returns when the folders/junction already exists */
             if (error.code === 'EEXIST' && error.errno === -17) {
                 return;
             }
             throw error;
         });
     });
 }

The new code is the second if statement. It seems like everything is working, but I'm not sure this is a complete answer without spending more time with the code.

kstewart83 avatar Oct 26 '19 04:10 kstewart83

@kstewart83 it makes sense and should be a PR because the issue stays opened since 2019 and indeed still occurs…

smileart avatar Apr 22 '22 16:04 smileart

Can confirm that it still exists. In my case I have package.json and my handlers in the same directory.

tibbe avatar Jun 30 '22 13:06 tibbe

I am getting also this issue, even when my package.json & project.json are in a parent directory to the handlers (I'm using nx, and the serverless api is in its own nx app folder). I've had to workaround it by manually deleting the .build folder as part of the deploy script.

dhartveld avatar Jul 01 '22 10:07 dhartveld

Im using npm workspaces and this seems to trigger the issue. If move the node_modules folder to the current directory everything works fine, but this isnt how workspaces work

lukemcgregor avatar Sep 25 '23 04:09 lukemcgregor

Any update on this?

I get the same issue with workspaces (pnpm)

tgdn avatar Oct 20 '23 16:10 tgdn

I removed serverless-plugin-typescript package and did test again. It seems it's worked!

Jpdsj avatar Mar 06 '24 01:03 Jpdsj