Skip to content

Bug: NodejsNpmEsbuildBuilder:NpmInstall fails with npm v12+ #893

Description

@keawade

Description:

When running sam build the NodejsNpmEsbuildBuilder:NpmInstall stage fails with an error of Error: NodejsNpmEsbuildBuilder:NpmInstall - NPM Failed: npm error code EUNKNOWNCONFIG.

The issue is that the npm install flags include a long deprecated --unsafe-perm parameter (Deprecated since npm v7). This was simply ignored for a long time but as of npm v12 npm now explicitly errors on unknown parameters.

Steps to reproduce:

On an existing esbuild-based SAM project:

  1. npm i -g npm@12
  2. sam build

Observed result:

2026-07-15 09:50:14,894 | NODEJS installing production dependencies in: /var/folders/kc/hyc5njk52pl4s9j1ksq4vxxc0000gq/T/tmp_d2jxm70                                                                                                                                          
2026-07-15 09:50:14,895 | executing NPM: ['npm', 'install', '-q', '--no-audit', '--no-save', '--unsafe-perm', '--production']                                                                                                                                                 
2026-07-15 09:50:16,568 | NodejsNpmEsbuildBuilder:NpmInstall failed                                                                                                                                                                                                           
Traceback (most recent call last):                                                                                                                                                                                                                                            
  File "aws_lambda_builders/workflows/nodejs_npm/actions.py", line 115, in execute                                                                                                                                                                                            
  File "aws_lambda_builders/workflows/nodejs_npm/npm.py", line 72, in run                                                                                                                                                                                                     
aws_lambda_builders.workflows.nodejs_npm.exceptions.NpmExecutionError: NPM Failed: npm warn config production Use `--omit=dev` instead.                                                                                                                                       
npm error code EUNKNOWNCONFIG                                                                                                                                                                                                                                                 
npm error Unknown cli flag:                                                                                                                                                                                                                                                   
npm error   - --unsafe-perm                                                                                                                                                                                                                                                   
npm error Run `npm help config` for supported options.                                                                                                                                                                                                                        
npm error A complete log of this run can be found in: <redacted>                                                                                                                                                         

During handling of the above exception, another exception occurred:                                                                                                                                                                                                           

Traceback (most recent call last):                                                                                                                                                                                                                                            
  File "aws_lambda_builders/workflow.py", line 374, in run                                                                                                                                                                                                                    
  File "aws_lambda_builders/workflows/nodejs_npm/actions.py", line 118, in execute                                                                                                                                                                                            
aws_lambda_builders.actions.ActionFailedError: NPM Failed: npm warn config production Use `--omit=dev` instead.                                                                                                                                                               
npm error code EUNKNOWNCONFIG                                                                                                                                                                                                                                                 
npm error Unknown cli flag:                                                                                                                                                                                                                                                   
npm error   - --unsafe-perm                                                                                                                                                                                                                                                   
npm error Run `npm help config` for supported options.                                                                                                                                                                                                                        
npm error A complete log of this run can be found in: <redacted>                                                                                                                                                         

Build Failed

Expected result:

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: macOS and Linux
  2. If using SAM CLI, sam --version: 1.163.0
  3. AWS region: N/A

Add --debug flag to any SAM CLI commands you are running

Metadata

Metadata

Assignees

No one assigned

    Labels

    stage/needs-triageAutomatically applied to new issues and PRs, indicating they haven't been looked at.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions