Reputation: 91
I'm trying out AWS SAM with nodeJS and Typescript using 'sam init', but when I want to build the example hello-world-typescript application using 'sam build', I get the following message:
Building codeuri: C:\RF\GitHub\rf-09-06\hello-world runtime: nodejs14.x metadata: {'BuildMethod': 'esbuild', 'BuildProperties': {'Minify': True, 'Target': 'es2020', 'Sourcemap': True, 'EntryPoints': ['app.ts']}} architecture: x86_64 functions: ['HelloWorldFunction']
Running NodejsNpmEsbuildBuilder:CopySource
Running NodejsNpmEsbuildBuilder:NpmInstall
Running NodejsNpmEsbuildBuilder:EsbuildBundle
Build Failed
Error: NodejsNpmEsbuildBuilder:EsbuildBundle - Esbuild Failed: cannot find esbuild
Any idea how to resolve it?
Thanks!
Upvotes: 9
Views: 19170
Reputation: 145
I was encountering this issue as well. I put sam build
as an npm script so that it looks at your project's node_modules
.
package.json
{
...
"scripts": {
"build": "sam build"
}
}
This way you don't have to install esbuild
globally. Then just npm run build
or yarn build
Upvotes: 3
Reputation: 319
You can install esbuild as development dependency and run sam build in package manager (ex: pnpm) scope
example:
pnpm sam build
Upvotes: 0
Reputation: 1145
It can be solved in either of the 2 ways:
Install esbuild globally using npm install -g esbuild
As mentioned in the AWS SAM github issues, move esbuild to non-dev dependency (npm install esbuild
) - Since esbuild will bundle your code, it won't be packaged in your Lambda.
PS: latest version of hello-world-typescript has this already corrected as mentioned in point 2.
Upvotes: 19
Reputation: 69
I had to install esbuild globally to get this working
npm install -g esbuild
Upvotes: 6