aspect-build / aspect-build/rules_esbuild

[Bug]: package.json browser field with file mapped to false fails to build

Open
#232 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Starlark
Stars
35
Forks
45
Avg merge
1d 1h
Merged PRs (30d)
1

Description

### What happened?

When bundling a npm package with package.json field `browsers` where it includes a filepath key mapped to `false`, `rules_esbuild` fails to build, but calling through `pnpm` succeeds. See repro linked below with a failure case, successful case, and a workaround where I disabled the esbuild sandbox plugin. The browser field is used to publish an isomorphic package that can operate both in node and browser environments. It can map some file that uses node apis to either another file that includes a replacement interface implementation or chooses to simply not include a replacement (which is what happens in this case).

See this npm package where I encountered this issue https://app.unpkg.com/@loaders.gl/worker-utils@3.4.15/files/package.json#L40

The error looks like:
```
✘ [ERROR] Could not read from file: /home/user/.cache/bazel/_bazel_user/b97476d719d716accead0f2d5b93104f/sandbox/processwrapper-sandbox/1753/execroot/__main__/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/@loaders.gl+worker-utils@3.4.15/node_modules/@loaders.gl/worker-utils/dist/esm/lib/process-utils/child-process-proxy
node_modules/.aspect_rules_js/@loaders.gl+worker-utils@3.4.15/node_modules/@loaders.gl/worker-utils/dist/esm/index.js:16:45:
16 │ ...hildProcessProxy } from './lib/process-utils/child-process-proxy';
```

The `package.json` file looks like:
```
{
"browser": {
"./dist/esm/lib/process-utils/child-process-proxy.js": false
},
}
```

Ideally, `rules_esbuild` behaves in the same as `esbuild` through `pnpm`.

### Version

Development (host) and target OS/architectures: Reproducible on Linux+Arm and Mac+Arm

Output of `bazel --version`: 8.1.1

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: Reproducible on 0.21.0 and latest 0.22.1

Language(s) and/or frameworks involved:

### How to reproduce

See repro code and instructions here https://github.com/chasestarr/bazel-js/tree/main/src/esbuild-entrypoint-browser-field-false

### Any other information?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the linked repro at src/esbuild-entrypoint-browser-field-false and compare its rules_esbuild build with the successful pnpm esbuild case. Inspect how the package.json browser mapping for ./dist/esm/lib/process-utils/child-process-proxy.js is handled, then verify that the build succeeds without disabling the esbuild sandbox plugin and matches esbuild behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.