sam build: NPM Failed when InlineCode is used
See original GitHub issueDescription:
When I create a template which contains at least one function, which uses InlineCode
, I cannot build the project with sam build
. It fails with the message:
Build Failed
Error: NodejsNpmBuilder:NpmPack - NPM Failed: npm ERR! code ENOLOCAL
npm ERR! Could not install from "../Users/username/path/to/template/folder" as it does not contain a package.json file.
I still can run ‘sam package’, although it requires from me an --s3-bucket
parameter to be provided, which makes no sense if I have only functions with InlineCode.
I also can deploy with sam deploy ...
if there is nothing, which I need to build first in the project.
But if I have a project with a mixture of functions, which have to be built and which have InlineCode, I cannot build it.
Steps to reproduce:
Create empty project with the runtime nodejs12.x
, delete all autogenerated JS code and leave only template file with the following content.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Sample SAM Template for bug report
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
InlineCode: "exports.handler = (event, context, callback) => { return { }; }"
Handler: index.handler
Runtime: nodejs12.x
Try to build it with sam build
.
Observed result:
The command fails with an error.
Build Failed
Error: NodejsNpmBuilder:NpmPack - NPM Failed: npm ERR! code ENOLOCAL
npm ERR! Could not install from "../Users/username/path/to/template/folder" as it does not contain a package.json file.
Expected result:
I expect the command goes through and there are build artefacts generated in .aws-sam
folder (in case template has more functions, which have to be built).
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: macOs mojave
sam --version
: SAM CLI, version 1.13.2
Add --debug flag to command you are running
sam build --debug
2020-12-11 11:10:51,822 | 'build' command is called
...
2020-12-11 11:10:51,868 | Building codeuri: . runtime: nodejs12.x metadata: {} functions: ['HelloWorldFunction']
2020-12-11 11:10:51,868 | Building to following folder /Users/xxx/tmp/mimas-test/.aws-sam/build/HelloWorldFunction
2020-12-11 11:10:51,869 | Loading workflow module 'aws_lambda_builders.workflows'
...
2020-12-11 11:10:51,888 | Found workflow 'NodejsNpmBuilder' to support capabilities 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
2020-12-11 11:10:51,888 | Running workflow 'NodejsNpmBuilder'
2020-12-11 11:10:51,888 | Running NodejsNpmBuilder:NpmPack
2020-12-11 11:10:51,888 | NODEJS packaging file:/Users/xxx/tmp/mimas-test to /var/folders/sn/zhmg6dt91f55k1fcd82xplwh0000gn/T/tmp696mt8f_
2020-12-11 11:10:51,888 | executing NPM: ['npm', 'pack', '-q', 'file:/Users/xxx/tmp/mimas-test']
2020-12-11 11:10:52,301 | NodejsNpmBuilder:NpmPack failed
Traceback (most recent call last):
File "/usr/local/Cellar/aws-sam-cli/1.13.2/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflows/nodejs_npm/actions.py", line 59, in execute
tarfile_name = self.subprocess_npm.run(["pack", "-q", package_path], cwd=self.scratch_dir).splitlines()[-1]
File "/usr/local/Cellar/aws-sam-cli/1.13.2/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflows/nodejs_npm/npm.py", line 85, in run
raise NpmExecutionError(message=err.decode("utf8").strip())
aws_lambda_builders.workflows.nodejs_npm.npm.NpmExecutionError: NPM Failed: npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../../../../../../Users/xxx/tmp/mimas-test" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/xxx/.npm/_logs/2020-12-11T10_10_52_284Z-debug.log
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/aws-sam-cli/1.13.2/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflow.py", line 269, in run
action.execute()
File "/usr/local/Cellar/aws-sam-cli/1.13.2/libexec/lib/python3.8/site-packages/aws_lambda_builders/workflows/nodejs_npm/actions.py", line 70, in execute
raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: NPM Failed: npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../../../../../../Users/xxx/tmp/mimas-test" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/xxx/.npm/_logs/2020-12-11T10_10_52_284Z-debug.log
Build Failed
Error: NodejsNpmBuilder:NpmPack - NPM Failed: npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../../../../../../xxx/xxx/tmp/mimas-test" as it does not contain a package.json file.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Hi, I can confirm in the version 1.17
sam build
goes through and deploys inline functions correctly with and withoutpackage.json
Closing this issue since the InlineCode improvement https://github.com/aws/aws-sam-cli/pull/2549 corrected the behaviour to support InlineCode usage. For anyone who experienced this issue please update the SAMCLI to version 1.16 or above!