esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

PathDisabled Flag is not exposed to plugins

Open ef4 opened this issue 1 year ago • 1 comments

If a plugin uses build.resolve() to invoke default resolving behavior and esbuild decides that the path is disabled by "browser" in package.json, the answer returned to the plugin does not include any indication that the path is supposed to be disabled. The plugin sees a successful resolution, with an only-partially-resolved filename in the result (which can be missing its extension).

If the plugin decide to leave this resolution result unchanged, esbuild will error while trying to load the incorrect path. The fact that this path was supposed to be disabled has been lost.

Here is a tiny reproduction: https://github.com/ef4/esbuild-bug-repro which produces:

[~/hacking/bug-repro2]$ pnpm build                                                                                                                                                                  [main]

> [email protected] build /Users/edward/hacking/bug-repro2
> node ./build.js

✘ [ERROR] Could not read from file: /Users/edward/hacking/bug-repro2/browser-disabled

    demo.js:1:19:
      1 │ import * as p from "./browser-disabled";
        ╵                    ~~~~~~~~~~~~~~~~~~~~

/Users/edward/hacking/bug-repro2/node_modules/.pnpm/[email protected]/node_modules/esbuild/lib/main.js:1476
  let error = new Error(text);
              ^

Error: Build failed with 1 error:
demo.js:1:19: ERROR: Could not read from file: /Users/edward/hacking/bug-repro2/browser-disabled

ef4 avatar Nov 12 '24 20:11 ef4

Oof, I just spent days tracking down this same thing. If anyone comes up with a good fix or workaround in the meantime, I'd love to know.

vpanta avatar Apr 23 '25 17:04 vpanta