serverless-heaven / serverless-webpack

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

Npm error while when packing bcrypt as an external modules #1063

Closed sudsbangs closed 2 years ago

sudsbangs commented 2 years ago

This is a (Bug Report / Feature Proposal)

Description

I am using "serverless-webpack": "^5.6.1", which uses bcrypt npm package. I have no issues in building the native modules using my docker which uses an alpine image mentioned here https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions#rhel-and-centos. However when theserverless-webpack starts packing external modules it comes back with error Error: npm install failed with code 1 at ChildProcess. (/usr/src/app/node_modules/serverless-webpack/lib/utils.js:91:16) at ChildProcess.emit (events.js:400:28) at ChildProcess.emit (domain.js:475:12) at maybeClose (internal/child_process.js:1058:16) at Socket. (internal/child_process.js:443:11) at Socket.emit (events.js:400:28) at Socket.emit (domain.js:475:12) at Pipe. (net.js:686:12)

For bug reports:

Similar or dependent issue(s):

Additional Data

× Stack dev-cloud failed to deploy (38s) Environment: linux, node 14.19.0, framework 3.1.1 (local), plugin 6.0.0, SDK 4.3.1 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. (/usr/src/app/node_modules/serverless-webpack/lib/utils.js:91:16) at ChildProcess.emit (events.js:400:28) at ChildProcess.emit (domain.js:475:12) at maybeClose (internal/child_process.js:1058:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:293:5)

vicary commented 2 years ago

npm install failed with code 1 means the installation has failed, the current implementation swallowed stderr from the npm process but you may manually run them in an alpine shell docker run -it --rm alpine to see what is the actual error.

From my experience it could be caused by bcrypt not having a pre-built binary for alpine, and docker alpine does not comes with build tools. Another possibility is that alpine does not come with the necessary crypto libraries.

Either way you should install them before running serverless-webpack, hence the subsequent npm install spwan by it.

sudsbangs commented 2 years ago

npm install failed with code 1 means the installation has failed, the current implementation swallowed stderr from the npm process but you may manually run them in an alpine shell docker run -it --rm alpine to see what is the actual error.

From my experience it could be caused by bcrypt not having a pre-built binary for alpine, and docker alpine does not comes with build tools. Another possibility is that alpine does not come with the necessary crypto libraries.

Either way you should install them before running serverless-webpack, hence the subsequent npm install spwan by it.

Thanks @vicary for answering. Yeah i did some pre-build for bcrypt using alphine docker image. I will try and give it a go as per your suggestion.