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
esbuildis installed as a development dependency in your project by running:bashnpm install esbuild --save-devThis command adds
esbuildto yournode_modules, ensuring it is available locally for your project. -
2. Update the Script Command to Use npx
If your
npm run buildscript usesesbuilddirectly, update it to usenpx. Modify your script inpackage.jsonas follows:bash{ "scripts": { "build": "npx esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets" } }Using
npxensures the command runs successfully by locating the local installation ofesbuild. -
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:
bashnpm install -
5. Debugging in GitHub Actions CI
Add the following step to your GitHub Actions workflow file to verify if
esbuildis installed correctly during the CI build process:bash- name: Verify esbuild installation run: npx esbuild --versionThis 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
esbuildas a development dependency. - Use
npx esbuildin 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.