After long hours searching for answers, I give up and ask for help, hopefully someone will also benefit from this.
Here is the problem, I have a project which uses AWS SAM. When i run sam build
it fails with NpmExecutionError
and a status code 255
. Here is where i first searched for
Stackoverflow sam build fail github sam build fail github (2) sam build fail
I tried with sam build --debug
and sam build -u --debug
, the latter gave me the error that esbuild is missing, but the former didn't gave me any error aside NPM Failed:
I tried to install esbuild globally with npm, then with brew, then on the project in dependencies
as well as devDependencies
.
I tried to update everything I installed with brew.
I tried to uninstall and re-install aws cli and sam cli.
I tried to rm node_modules and install again
I tried to update npm
Here are some information about my setup
npm => 9.1.1
node => v16.17.0
aws cli => aws-cli/2.8.12 Python/3.9.11 Darwin/22.1.0 exe/x86_64 prompt/off
sam => SAM CLI, version 1.63.0
esbuild => 0.15.14
Here are the screenshot of the error log
sam build -u --debug
PS: what is hidden are information about telemetry data such as session_id, request_id, etc...
A collegue of mine successfully build the exact same project with the exact same configuration which confuses me.
Also I have two folder, one that contains a template.yml with AWS::Serverless::Api
(the one who fails, see screenshot) but I also have another folder with a template.yml with AWS::Serverless::LayerVersion
which successfully build
Thanks to everyone who are willing to help me
EDIT: I tried using Hello world project from AWS SAM (typescript, zip) and the build even fail for this project
EDIT 2: I tried to comment the Metadata part containing esbuild config and the build success so I don't know why it fails with esbuild
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello-world/
Handler: app.lambdaHandler
Runtime: nodejs16.x
Architectures:
- x86_64
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get
# Metadata: # Manage esbuild properties
# BuildMethod: esbuild
# BuildProperties:
# Minify: true
# Target: "es2020"
# # Sourcemap: true # Enabling source maps will create the required NODE_OPTIONS environment variables on your lambda function during sam build
# EntryPoints:
# - app.ts
To solve this problem, I removed Node from brew as I use the n
package, then I installed the latest version of Node using n v18.12.1
and by doing this it updated my npm version to 8.19.2
which seemed to have solved the problem
I also removed esbuild both from npm and brew package, then I reinstalled it thought npm -g install esbuild