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

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

Error: npm install failed with code 1 at ChildProcess.<anonymous> (/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"

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 28 (7 by maintainers)

Most upvoted comments

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

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)

@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”)

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

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.

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

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.

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

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
 

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.

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

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??