Fixing 'esbuild not found' Error in GitHub Actions

· CI/CD & GitHub Actions · By Zeeshan Ahmad

Fixing "esbuild Not Found" Error in GitHub Actions CI Pipeline

Understanding the Problem

If you're encountering the error message sh: 1: esbuild: not found during your CI build process, it indicates that the esbuild binary isn't available in the system's path. This usually occurs because esbuild has not been correctly installed or is not accessible.

Solution Steps

Follow these steps to resolve the issue:

  • 1. Install esbuild as a Development Dependency

    Ensure that esbuild is installed as a development dependency in your project by running:

    bash
    npm install esbuild --save-dev

    This command adds esbuild to your node_modules, ensuring it is available locally for your project.

  • 2. Update the Script Command to Use npx

    If your npm run build script uses esbuild directly, update it to use npx. Modify your script in package.json as follows:

    bash
    {
      "scripts": {
        "build": "npx esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets"
      }
    }

    Using npx ensures the command runs successfully by locating the local installation of esbuild.

  • 3. Check Node Version Compatibility

    Ensure that the version of Node.js you are using is compatible with esbuild. Outdated versions might cause compatibility issues.

  • 4. Re-run npm Install

    Run the following command to ensure all dependencies are installed correctly:

    bash
    npm install
  • 5. Debugging in GitHub Actions CI

    Add the following step to your GitHub Actions workflow file to verify if esbuild is installed correctly during the CI build process:

    bash
    - name: Verify esbuild installation
      run: npx esbuild --version

    This will help you diagnose issues early.

Conclusion

By following these steps, you can resolve the esbuild not found error and ensure your CI pipeline runs smoothly:

  • Install esbuild as a development dependency.
  • Use npx esbuild in your build script.
  • Ensure Node.js is updated and compatible.
  • Reinstall dependencies with npm install.
  • Add a debugging step in GitHub Actions to verify the installation.

Related articles

Home · All Tools · Blog