Toba
Toba

Reputation: 91

AWS SAM - Esbuild Failed: cannot find esbuild

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

Answers (5)

TheBigFriezy
TheBigFriezy

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

king.reflex
king.reflex

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

user11666461
user11666461

Reputation: 1145

It can be solved in either of the 2 ways:

  1. Install esbuild globally using npm install -g esbuild

  2. 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

Gordon Anderson
Gordon Anderson

Reputation: 69

I had to install esbuild globally to get this working npm install -g esbuild

Upvotes: 6

Karol D.
Karol D.

Reputation: 27

install esbuild, you can use npm for that

npm install esbuild

Upvotes: 1

Related Questions