6

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!

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71
Toba
  • 61
  • 1
  • 3
  • I would suggest using @vercel/ncc for a less disruptive build process. You can keep the `node_modules` and other files like `package.json` as is in their original location, instead of moving stuff around. – sayandcode Jan 31 '23 at 06:59

5 Answers5

12

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.

user11666461
  • 761
  • 7
  • 12
  • This should be the preferred answer! – BAD_SEED Nov 27 '22 at 23:19
  • This actually solved the problem for me. [AWS CodeBuild] – saibbyweb Dec 05 '22 at 12:00
  • Neither solution works. Upon trying to install esbuild globally, the `install.js` file under `esbuild` can't be found within the global node_modules folder. Using NVM results in same, just within the nvm global node_modules folder. Trying to install locally results in same error, within the local node_modules folder. – Caleb Jay Aug 31 '23 at 06:06
6

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

  • BEWARE: This fixes the problem but it might introduce inconsistencies among versions of esbuild. Please, refer the @user11666461 for better explanation – BAD_SEED Nov 27 '22 at 23:21
1

install esbuild, you can use npm for that

npm install esbuild
Karol D.
  • 27
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 11 '22 at 17:43
  • It has been installed, but still no luck. What else it can be? – Toba Jun 14 '22 at 11:51
0

You can install esbuild as development dependency and run sam build in package manager (ex: pnpm) scope

example:

pnpm sam build

king.reflex
  • 313
  • 4
  • 10
0

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

TheBigFriezy
  • 116
  • 4