NodejsNpmEsbuildBuilder:NpmInstall - NPM Failed: npm WARN config production Use `--omit=dev` instead
- Dominant language
- Python
- Stars
- 380
- Forks
- 161
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 2
Description
### Description:
It looks like at some point npm deprecated the `--production` parameter and started WARNing about it in stderr, which seems to break `sam build`.
I'm not sure which version of npm introduced that but [the relevant range](https://github.com/npm/cli/blame/2e4b4ad8bef158def1b2302846ab294fe7a83de4/workspaces/config/lib/definitions/definitions.js#L1643-L1648) in npm code git-blames back to a couple years ago.
I found `--production` still in unconditional use in the corresponding builder {[actions.py:111](https://github.com/aws/aws-lambda-builders/blob/c23710f473a718f47bc19070ca6cd6afdfbc950f/aws_lambda_builders/workflows/nodejs_npm/actions.py#L111)}. I think it needs to be upgraded to `--omit=dev` depending on the npm version.
### Steps to reproduce:
`sam build` with a node_modules layer and npm version >= 9.6.7
Alternatively, just run npm i --production and observe the same warning. Clearly, it's not supposed to be called with --production anymore.
### Observed result:
```
Running NodejsNpmEsbuildBuilder:CopySource
Running NodejsNpmEsbuildBuilder:CopySource
Running NodejsNpmEsbuildBuilder:NpmInstall
Running NodejsNpmEsbuildBuilder:NpmInstall
Running NodejsNpmEsbuildBuilder:NpmInstall
Running NodejsNpmEsbuildBuilder:EsbuildBundle
Running NodejsNpmEsbuildBuilder:EsbuildBundle
Running NodejsNpmEsbuildBuilder:EsbuildBundle
Build Failed
Error: NodejsNpmEsbuildBuilder:NpmInstall - NPM Failed: npm WARN config production Use `--omit=dev` instead.
```
### Expected result:
Wouldn't expect to see the warning, and wouldn't expect it to be treated as an error.
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
1. OS: `image: node:18`
2. If using SAM CLI, `sam --version`: 1.98.0
3. AWS region: us-east-1
> `Add --debug flag to any SAM CLI commands you are running`
So the CI/CD pipeline failed, and I went to create this bug report, and then I read about --debug and added it to sam commands in the pipeline... But it did not fail this time! I'm confused and I cannot reproduce this issue reliably. Still, just looking at the code of aws-lambda-builders and npm, the problem seems to be present.
Contributor guide
Assessment
This issue has not been assessed yet.