serverless / serverless-plugin-typescript

Serverless plugin for zero-config Typescript support
MIT License
785 stars 227 forks source link

EEXIST when invoking locally for the second time #152

Open SkyLeite opened 5 years ago

SkyLeite commented 5 years ago

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.

Selion05 commented 5 years ago

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

Weetbix commented 5 years ago

@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.

JackCuthbert commented 5 years ago

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

SkyLeite commented 5 years ago

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.

Selion05 commented 5 years ago

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

Ryanauger95 commented 5 years ago

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

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

kstewart83 commented 5 years ago

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.

smileart commented 2 years ago

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

tibbe commented 2 years ago

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

dhartveld commented 2 years ago

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.

lukemcgregor commented 1 year ago

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

tgdn commented 1 year ago

Any update on this?

I get the same issue with workspaces (pnpm)

Jpdsj commented 8 months ago

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

pitzcarraldo commented 3 months ago

Still exists.

I've solved with this way.

package.json

"scripts": {
...
    "prelocal": "rimraf .build",
    "local": "serverless invoke local --function function_name --stage local",
...
}