aws-sam-cli: Sam Build Failed: NodejsNpmBuilder:NpmPack

After trying a SAM project using python, I suddenly need to create a package.json file for each lambda function.

Otherwise, I will get an error:

Build Failed
Error: NodejsNpmBuilder:NpmPack - NPM Failed: npm ERR! code ENOLOCAL

I don’t need any node_modules for my lambda function, so I would like not to include it in my folder.

For each function, this script will run.

Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrc
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

The differences in command line:

First project:

$ sam build
Build Succeeded
Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided

Second project:

$ sam build
Building resource 'HelloWorldFunction'
Running NodejsNpmBuilder:NpmPack
Build Failed
Error: NodejsNpmBuilder:NpmPack - NPM Failed: npm ERR! code ENOLOCAL
npm ERR! Could not install from "<<path>>" as it does not contain a package.json file.