agutoli / serverless-layers

Serverless.js plugin implementing AWS Lambda Layers, reducing lambda size, warm-up, and deployment time.
MIT License
230 stars 54 forks source link

package.json file is not actually copied over in WSL2 #164

Closed ShlomoVinny closed 8 months ago

ShlomoVinny commented 8 months ago

I've been using serverless-layers for a while and recently have a problem deploying or packaging any projects that use this plugin. I'm using: Ubuntu 22.04.4 LTS in WSL2 I added a couple logs to Dependencies.js for key: "copyProjectFile", to make sure the paths are correct when running. The paths are correct and I can see that the plugin actually deletes the old folder in the /.serverless/ dir, creates a new /layers/nodejs/ in it instead, but it does not copy over the package.json file from the specified dependenciesPath. No errors are thrown, I added a log to the callback to make sure it executes.

       var destFile = path.join(_this2.layersPackageDir, fileName || path.basename(filePath));
        console.info("Copying:", filePath, "To:", destFile);
        copyFile(filePath, destFile, function (copyErr) {
          if (copyErr) throw copyErr;
          console.log("Copied!");
          return resolve();
        });

The log says:

Copying: /mnt/d/myPath/layers/package.json To: /mnt/d/myPath/.serverless/layers/nodejs/package.json Copied!

But I can see no file has actually been copied and the folder stays empty.

Furthermore, since no error is thrown on copying, even though the file was not copied, the script continues running and tries to install dependencies anyway, but since there's no package.json in the cwd specified for the run command, it falls back to the main package.json of the entire project which is incorrect and actually uses pnpm, so it contains "workspace" version names which cause this error, eventually:

Error: Command failed: npm install --production --only=prod npm WARN config production Use --omit=dev instead. npm WARN config only Use --omit=dev to omit dev dependencies from the install. npm ERR! code EUNSUPPORTEDPROTOCOL npm ERR! Unsupported URL Type "workspace:": workspace:1.0.0

Obviously the package.json I'm trying to install has no "workspace" version names in it.

ShlomoVinny commented 8 months ago

Actualyl works just fine, it was another issue that was causing this:

https://github.com/agutoli/serverless-layers/issues/165