Skip to content

Build Failure in Lesson 4 Due to Missing esbuild Dependency - Solution Provided #3

@Warren-Byron

Description

@Warren-Byron

Problem

I am referring to the section "Local testing" in Lesson 4. When I tried to run the command:

sam build beta-features

I encountered the following error:

Build Failed
Error: NodejsNpmEsbuildBuilder:EsbuildBundle - Esbuild Failed: Cannot find esbuild. esbuild must be installed on the host machine to use this feature. It is recommended to be installed on the PATH, but can also be included as a project dependency.

Analysis

The error indicates that the esbuild package is not found. This typically happens because esbuild is listed under devDependencies in the package.json, which are not installed in some environments, particularly in production or when running certain build tools.

Fix

To resolve this issue, I had to move the esbuild package from devDependencies to dependencies in the /backend/package.json file. Here is the modified section:

...
  "dependencies": {
    "@aws-sdk/client-dynamodb": "^3.95.0",
    "@aws-sdk/client-sqs": "^3.95.0",
    "@aws-sdk/lib-dynamodb": "^3.95.0",
    "nodemailer": "^6.7.5",
    "esbuild": "^0.14.14"
  },
  "devDependencies": {
    "@types/aws-lambda": "^8.10.92",
    "@types/node": "^17.0.13",
    "ts-node": "^10.4.0",
    "typescript": "^4.6.4"
  },
...

Additional Note

  • This solution was derived from a Stack Overflow post which suggested ensuring esbuild is installed as a dependency rather than a devDependency.
  • You could also install esbuild globally using
npm install -g esbuild

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions