Skip to content

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

Description

@chasestarr

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions