evanw / evanw/esbuild

PathDisabled Flag is not exposed to plugins

Open
#3,976 1 comment 4 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

If a plugin uses `build.resolve()` to invoke default resolving behavior and esbuild decides that the [path is disabled by "browser" in package.json](https://github.com/evanw/esbuild/blob/9eca46464ed5615cb36a3beb3f7a7b9a8ffbe7cf/internal/logger/logger.go#L329), 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]

> esbuild-bug@1.0.0 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/esbuild@0.24.0/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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.