serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack
MIT License
1.72k stars 414 forks source link

Error: npm install failed with code 1 for installing bitbucket repository(typescipt project) as package in my ts project #955

Closed himharsh1997 closed 2 years ago

himharsh1997 commented 3 years ago

Error --------------------------------------------------

Error: npm install failed with code 1 at ChildProcess. (/opt/atlassian/pipelines/agent/build/node_modules/serverless-webpack/lib/utils.js:91:16) at ChildProcess.emit (events.js:210:5) at ChildProcess.EventEmitter.emit (domain.js:475:20) at maybeClose (internal/child_process.js:1021:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

 For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

Get Support -------------------------------------------- Docs: docs.serverless.com Bugs: github.com/serverless/serverless/issues Issues: forum.serverless.com

Your Environment Information --------------------------- Operating System: linux Node Version: 12.14.0 Framework Version: 2.17.0 (local) Plugin Version: 4.6.0 SDK Version: n/a Components Version: 3.17.0

  "serverless-webpack": "5.3.5",
  "webpack": "^4.29.0",
  "webpack-node-externals": "^1.7.2"
j0k3r commented 3 years ago

Could you update to latest serverless-webpack & webpack? Could you also share your serverless.yml?

Also, don't remove stuff from the issue template, it avoid us asking common question like the two above ...

himharsh1997 commented 3 years ago

Will update for both.

My points:

  1. But when I try to deploy project from local usingsls deploy the project got deployed successfully.
  2. But when I try to deploy using bitbucket pipeline with node:12.14.0 it caused this error
  3. In my typescript project I installing another typescript project(which having postinstall script 'tsc') inside node_modules.

Sorry can't give yml file info as it belong to some company.

himharsh1997 commented 3 years ago

Could you update to latest serverless-webpack & webpack? Could you also share your serverless.yml?

Also, don't remove stuff from the issue template, it avoid us asking common question like the two above ...

Not working for me when using these

  "serverless-webpack": "5.5.4",
    "webpack": "5.52.1",
j0k3r commented 3 years ago

Well, if it works locally and not on the pipeline, I guess the problem is in the pipeline and not in the library. You should check node version, npm version, installing the project using npm install to see if it goes well, etc.

himharsh1997 commented 3 years ago

Could it be caused due to installed other typescript project as dependency in my project as last deployment was successful and after this change it giving this error??

stupiginproducton commented 2 years ago

@himharsh1997 I encountered the same error too after installed other private typescript package.

zirkelc commented 2 years ago

I have the same issue running on a GitHub actions workflow. I think it's related to this issue: https://github.com/serverless-heaven/serverless-webpack/issues/781

The issue pops up on Node 14 and not on Node 16. I guess it's related to NPM v6 vs v7 and the output of the npm ls -prod -json -depth=1 command thats being executed by serverless-webpack.

afcode123 commented 2 years ago

I am having this exact issue when running sls deploy locally. Previously it was working fine, but now it fails on npm install. Any ideas how to fix it? Or how can I get more info on the issue as "npm install failed with code 1" does not tell much

asset src/apollo-server.js 236 KiB [emitted] (name: src/apollo-server)
orphan modules 103 KiB [orphan] 55 modules
runtime modules 937 bytes 4 modules
built modules 103 KiB [built]
  ./src/apollo-server.ts + 55 modules 103 KiB [not cacheable] [built] [code generated]
  external "fs" 42 bytes [built] [code generated]
  external "util" 42 bytes [built] [code generated]
webpack compiled successfully in 3897 ms
Serverless: Invoke webpack:package
Serverless: WARNING: Could not determine version of module jsonwebtoken
Serverless: WARNING: Could not determine version of module .prisma
Serverless: Package lock found - Using locked versions
Serverless: Packing external modules: reflect-metadata@^0.1.13, apollo-server-lambda@^3.3.0, graphql@^15.5.3, type-graphql@^1.1.1, class-validator@^0.13.1, jsonwebtoken, jwks-rsa@^2.0.5, @prisma/client@^2.30.0, graphql-fields@^2.0.3, uuid@^8.3.2, .prisma, axios@^0.21.4, dayjs@^1.10.7

 Error ---------------------------------------------------

  Error: npm install failed with code 1
      at ChildProcess.<anonymous> (<path>/node_modules/serverless-webpack/lib/utils.js:91:16)
      at ChildProcess.emit (events.js:210:5)
      at ChildProcess.EventEmitter.emit (domain.js:475:20)
      at maybeClose (internal/child_process.js:1021:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.13.1
     Framework Version:         2.66.1 (local)
     Plugin Version:            5.5.1
     SDK Version:               4.3.0
     Components Version:        3.18.0
vicary commented 2 years ago

@afcode123 serverless-webpack will try to create a single-use package.json and perform npm install with it, part of the reason is to ensure dependency completeness when you use forceInclude and forceExclude.

One common cause of this error comes from including or excluding packages which is not already installed in your root package.json.

Arunaliyanaarachchi commented 2 years ago

Delete packge-lock.JSON and node module folder. then npm install

james-ingold commented 2 years ago

Not sure if this will help anyone but was having the same issue in bitbucket with serverless@2. I downgraded my node image in the pipeline from 17.4 to 14.4 and deployed successfully without npm install failed with code 1 issue.

moroine commented 2 years ago

I faced this issue, and it's related to npm install command. Try to go in the .webpack and manually try npm install

vicary commented 2 years ago

I see this question in a constant rate. We can either piping the packager's stderr outwards, or simply document this behavior.

A PR is definitely appreciated.

vishnu-buildd commented 2 years ago

A much better error would be appreciated. I use a private package. My build fails, but deploy works. i.e. sls package fails while sls deploy works. I am not really sure how to even debug this better.

mrjasan commented 2 years ago

I'm having the same issue deploying on CircleCI

Package lock found - Using locked versions
Packing external modules: @aws-sdk/client-cloudwatch@^3.72.0, @aws-sdk/client-dynamodb@^3.72.0, @aws-sdk/lib-dynamodb@^3.72.0, @aws-sdk/smithy-client, @aws-sdk/types,  deepmerge

× Stack *******-prod failed to deploy (9s)
Environment: linux, node 12.20.2, framework 3.14.0, plugin 6.2.1, SDK 4.3.2
Credentials: Local, environment variables
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Error: npm install failed with code 1
    at ChildProcess.<anonymous> (/home/circleci/app/node_modules/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)
ViniciusAlberkovics commented 2 years ago

Try to add the packager property in the serverless-webpack configuration informing the package manager used in the project. (npm|yarn).

Sample: serverless.ts

  custom: {
    webpack: {
      webpackConfig: "./webpack.config.js",
      packager: "npm",
      includeModules: true,
    },

serverless.yml

custom:
  webpack:
    webpackConfig: "webpack.config.js"
    packager: "npm"
     includeModules: true
HaaLeo commented 2 years ago

I have the exact same issue as @mrjasan when running sls package on AWS CodeBuild.

ViniciusAlberkovics commented 2 years ago

I had the same issue with npm@8.11.0 in Azure DevOps Pipeline, I solved it by downgrading npm to version 8.10.0.

HaaLeo commented 2 years ago

Thx @ViniciusAlberkovics that fixed it for me.

mrjasan commented 2 years ago

Update - my issue was related to using a private package and not setting up the right credentials. Everything else worked fine after I fixed that.

vicary commented 2 years ago

Everyone is welcomed for contribution in either,

  1. Piping error messages from the packager child process, or
  2. Document this behavior and lead users to do a test install.

Please open a PR directly and ping us for reviewing.

But the plugin is working as expected, so I'll close for now.

Others may continue to add more scenarios in the comments to aid future contributors for the PR.

AlexRRR commented 2 years ago

@vicary

  1. Piping error messages from the packager child process

would you happen to know how to manually do this? I am having the same issue npm install failed with code 1 described here but I am not able to tell the reason, does not seem to relate to what others have experienced. thanks!

vicary commented 2 years ago

@AlexRRR you would start from these two methods,

https://github.com/serverless-heaven/serverless-webpack/blob/6975610cccf87ce8f69389c74c8546de4123aabf/lib/packagers/yarn.js#L120-L140

https://github.com/serverless-heaven/serverless-webpack/blob/89c629e4d49ebdba5af9f69330f155df287d6506/lib/packagers/npm.js#L119-L128

Because Util.spawnProcess is already resolving with stdout and stderr, you only need to change the .return() and add to the logs in the following section.

https://github.com/serverless-heaven/serverless-webpack/blob/5d5723ea3ed1b97fbeebb79ddbeaaaeee7693404/lib/packExternalModules.js#L395-L402

AlexRRR commented 2 years ago

@vicary thank you so much, with that I found out that my problem when running the sls webpack command on CI for external modules was related to our private npm repo which requires auth, since there was no .npmrc setup on the .webpack directory it was no able to do the npm install, solved by copying the .npmrc file to the home directory of the user running the CI build.

it indeed would have been so much easier if the output was not swallowed by the child process, but again super grateful for your help!

vrashankraom commented 1 year ago

image (1)

Try to press the clear runner cache button at top, as seen in this image. This worked for me. Note:- Only project maintainers has access to this button.

ahmadysalah commented 1 year ago

Dont delete package lock file after install dependancy or use yarn to install sls service

adumat commented 11 months ago

@AlexRRR and @vicary thanks, i've found that my failing was because yarn 2 in ci by default set YARN_ENABLE_IMMUTABLE_INSTALLS to true (that in my case is not exactly immutable "by design")

apmechev commented 6 months ago

same issue/resolution as @adumat, we migrated from npm to yarn and the package broke. Here's the config fix for us

---
  webpack:
    packager: "yarn"
    packagerOptions:
      noFrozenLockfile: true
---
syn2ed commented 2 months ago

image (1)

Try to press the clear runner cache button at top, as seen in this image. This worked for me. Note:- Only project maintainers has access to this button.

This worked for me, thank you !