Skip to content

fix: bundle prettier into dist by removing it from esbuild external list#543

Merged
Jamie-BitFlight merged 4 commits intomainfrom
copilot/fix-prettier-module-not-found-error
Apr 29, 2026
Merged

fix: bundle prettier into dist by removing it from esbuild external list#543
Jamie-BitFlight merged 4 commits intomainfrom
copilot/fix-prettier-module-not-found-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

The action fails immediately on startup with ERR_MODULE_NOT_FOUND: Cannot find package 'prettier' because esbuild was configured to treat prettier as external, leaving it unbundled. At runtime in user workflows, only dist/ is present — no node_modules — so the import resolves to nothing regardless of the pretty input value.

Changes

scripts/esbuild.mjs — remove prettier from the external array:

-    external: ['prettier'],
+    external: [],

prettier is already a dependency (not devDependency) in package.json, so bundling it is correct. The resulting dist/bin/index.js grows to ~29MB but is fully self-contained.

__tests__/integration-bundled-binary.test.ts — added a regression test that reproduces the original failure path:

  • Copies the binary into an isolated temp directory with no node_modules anywhere in the directory hierarchy (mirroring the GitHub Actions runner environment where only dist/ is deployed)
  • Runs the binary from that isolated directory
  • Asserts that stderr contains no ERR_MODULE_NOT_FOUND and that the binary exits successfully with a generated README

The test was validated to fail against a binary built with external: ['prettier'] (reproducing the exact error from the issue) and pass against the fixed binary.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 81.76% 771 / 943
🔵 Statements 81.85% 776 / 948
🔵 Functions 83.19% 99 / 119
🔵 Branches 76.66% 368 / 480
File CoverageNo changed files found.
Generated in workflow #598 for commit 576a50c by the Vitest Coverage Report Action

Copilot AI changed the title [WIP] Fix action execution failure with ERR_MODULE_NOT_FOUND for prettier fix: bundle prettier into dist by removing it from esbuild external list Apr 29, 2026
Copilot AI requested a review from Jamie-BitFlight April 29, 2026 09:36
@Jamie-BitFlight Jamie-BitFlight marked this pull request as ready for review April 29, 2026 09:37
Copilot AI review requested due to automatic review settings April 29, 2026 09:37
@Jamie-BitFlight
Copy link
Copy Markdown
Contributor

@copilot did the validation tests test the failure path accurately. did you trigger the error without the fix first to identify how the failure occurred

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime startup failure in the published GitHub Action by ensuring prettier is bundled into the generated dist/bin/index.js, so the action can run in user workflows where node_modules is not present.

Changes:

  • Remove prettier from the esbuild external list so it is included in the bundle.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot did the validation tests test the failure path accurately. did you trigger the error without the fix first to identify how the failure occurred

No, I didn't reproduce the failure path first in my initial fix. I've now done that explicitly in commit 9a11fa2.

Here's what was done to validate the failure path:

  1. Reproduced the original bug: Restored external: ['prettier'] in esbuild.mjs, rebuilt the binary (13MB), copied it to an isolated temp directory with no node_modules, and ran it — produced the exact error from the issue:

    Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'prettier' imported from .../index.js
    

    The key was copying the binary to a temp dir with no parent node_modules. Simply changing cwd isn't sufficient — Node.js resolves external modules relative to the binary's own location, walking up the directory tree. The GitHub Actions runner fails because no node_modules/prettier exists anywhere in the hierarchy above dist/bin/index.js.

  2. Added a regression test (__tests__/integration-bundled-binary.test.ts) that:

    • Copies the binary into an isolated temp dir (no node_modules in the path)
    • Runs it from that temp dir
    • Asserts stderr contains no ERR_MODULE_NOT_FOUND

    Confirmed the test fails against the broken binary (with external: ['prettier']) and passes against the fixed one.

@Jamie-BitFlight
Copy link
Copy Markdown
Contributor

@copilot your changes are failing the ci tests. please lint and format

auto-merge was automatically disabled April 29, 2026 09:51

Head branch was pushed to by a user without write access

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot your changes are failing the ci tests. please lint and format

Fixed in 576a50c — removed the unused stdout variable that was triggering the lint/correctness/noUnusedVariables biome error. The execSync return value is now discarded (only stderr and exitCode from the catch block are needed).

@Jamie-BitFlight Jamie-BitFlight merged commit a78b8bd into main Apr 29, 2026
10 checks passed
@Jamie-BitFlight Jamie-BitFlight deleted the copilot/fix-prettier-module-not-found-error branch April 29, 2026 09:53
@Jamie-BitFlight
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.10.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Jamie-BitFlight Jamie-BitFlight added the released This issue/pull request has been released. label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released This issue/pull request has been released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Action fails to execute with ERR_MODULE_NOT_FOUND for prettier

3 participants