Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm ls errors when using npm 7 workspaces #781

Closed
mikejpeters opened this issue Apr 11, 2021 · 5 comments · Fixed by #782
Closed

npm ls errors when using npm 7 workspaces #781

mikejpeters opened this issue Apr 11, 2021 · 5 comments · Fixed by #782
Milestone

Comments

@mikejpeters
Copy link
Contributor

mikejpeters commented Apr 11, 2021

This is a Bug Report

Description

  • What went wrong?

    Running serverless deploy or serverless package outputs an error when using this plugin with includeModules: true and npm 7 workspaces.

  • What did you expect should have happened?

    The plugin should work with npm 7 workspaces, even if npm ls results in "missing" errors.

  • What was the config you used?

    In webpack.config.js define at least one external module, and in serverless.yml enable includeModules:

    custom:
      webpack:
        includeModules: true

    I've created a minimum example repo: boundstate/serverless-webpack-npm-7-example

  • What stacktrace or error message from your provider did you see?

     Error: npm ls -prod -json -depth=1 failed with code 1
        at ChildProcess.<anonymous> (serverless-webpack/lib/utils.js:91:16)
        at ChildProcess.emit (events.js:314:20)
        at ChildProcess.EventEmitter.emit (domain.js:483:12)
        at maybeClose (internal/child_process.js:1022:16)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
    

Similar or dependent issue(s):

Additional Data

  • Serverless-Webpack Version you're using: 5.4.1
  • Webpack version you're using: 5.24.2
  • Serverless Framework Version you're using: 2.35.0
  • Operating System: Ubuntu 20.10
  • Stack Trace (if available): (see above)

I believe this issue happens because in npm 7 they changed the output of the npm ls command,
which is used by this plugin to get prod dependencies.

The errors about "missing" dependencies (because they are hoisted in a monorepo) are not handled as expected because the command outputs additional error lines.

npm ls -prod -json -depth=1

npm 6.x stderr:

npm ERR! missing: @foo/bar@^1.2.3, required by [email protected]

npm 7.x stderr:

+ npm ERR! code ELSPROBLEMS
  npm ERR! missing: @foo/bar@^1.2.3, required by [email protected]
+ {
+   "error": {
+     "code": "ELSPROBLEMS",
+     "summary": "missing: @foo/bar@^1.2.3, required by [email protected]",
+     "detail": ""
+   }
+ }

+ npm ERR! A complete log of this run can be found in:
+ npm ERR!     debug.log

I'm happy to submit a PR, but I would appreciate some suggestions on the best solution.

In the current code, stderr lines starting with npm ERR! extraneous / npm ERR! missing / npm ERR! peer dep missing are ignored. Maybe it should also ignore npm ERR! code ELSPROBLEMS and then all lines after the opening { (start of JSON and error summary), but it's hard to know if this would ever hide valid errors the user needs to be aware of.

@mikejpeters mikejpeters changed the title npm ls errors when using npm 7 npm ls errors when using npm 7 workspaces Apr 11, 2021
@j0k3r
Copy link
Member

j0k3r commented Apr 12, 2021

I'm happy to submit a PR, but I would appreciate some suggestions on the best solution.

Looks like you found the solution on your own 👍

@j0k3r j0k3r added this to the 5.4.2 milestone Apr 12, 2021
@joepjoosten
Copy link

Ran into exactly the same problem

@lepirlouit
Copy link

Ran into exactly the same problem
this was the folder architecture

package-lock.json
package.json
|_folder1
   |_folder2
      |_serverless.yml
         package.json -> ../../package.json
         package-lock.json -> ../../package-lock.json

npm install was executed from root folder
serverless deploy was executed from folder2

solved by removing the two symlinks

@jooleeanh
Copy link

I had this issue because I had libraries in my "dependencies" that were not used anywhere (not sure if it was caused by a specific library, or by the presence of unused libraries, probably the latter). Removing them fixed it.

@ruucm
Copy link

ruucm commented Nov 20, 2023

don't know why but in my case I needed to add package-lock.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants