aspect-build / aspect-build/rules_js

[Bug]: `public_hoist_packages` does not hoist dependencies in `bazel-bin/node_modules`

Open
#1,419 1 comment 0 reactions 0 assignees View on GitHub
bug need: investigation
Dominant language
Starlark
Stars
378
Forks
183
Avg merge
1d 9h
Merged PRs (30d)
32

Description

### What happened?

I am migrating my vue project to `bazel` and `rules_js`.

I used `@vue/cli-service@4.5.19` which transitively uses plugins such as `@vue/cli-plugin-babel`, but without declaring it in `dependencies`. So I plan to use `public_hoist_packages` to make `@vue/cli-service` aware of `@vue/cli-plugin-babel`.
But the `public_hoist_packages` field did not hoist `@vue/cli-plugin-babel` in `bazel-bin/node_modules`.

Based on docs, `public_hoist_packages` will do the same thing as `public-hoist-pattern` in `pnpm`. I also tried [bazelbuild/examples/frontend](https://github.com/bazelbuild/examples/blob/main/frontend/MODULE.bazel#L22) and didn't see changes in `bazel-bin/node_modules` either.

### Version

Development (host) and target OS/architectures:
`x86_64 GNU/Linux ubuntu focal`

Output of `bazel --version`:
`bazel 7.0.0`

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file:
`rules_js` version is `1.34.1`

### How to reproduce
I built all targets in `bazelbuild/examples/frontend` and didn't see hoisting in `bazel-bin/node_modules`
```shell
tusen@desk-0181:~/examples/frontend$ bazel build ...
INFO: Analyzed 69 targets (1236 packages loaded, 10039 targets configured).
INFO: Found 69 targets...
INFO: Elapsed time: 9.104s, Critical Path: 0.09s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
tusen@desk-0181:~/examples/frontend$ ls bazel-bin/node_modules/
jsdom vitest
```
I tried `pnpm i` with `public_hoist_pattern` which did the hoisting in `node_modules` directory.
```shell
tusen@desk-0181:~/examples/frontend$ pnpm i
Scope: all 7 workspace projects
Lockfile is up to date, resolution step is skipped
Already up to date
Done in 1.6s
tusen@desk-0181:~/examples/frontend$ ls node_modules/
@next eslint-import-resolver-typescript eslint-plugin-jsx-a11y eslint-utils
eslint eslint-module-utils eslint-plugin-react eslint-visitor-keys
eslint-config-next eslint-plugin-flowtype eslint-plugin-react-hooks jsdom
eslint-config-react-app eslint-plugin-import eslint-plugin-testing-library vitest
eslint-import-resolver-node eslint-plugin-jest eslint-scope
tusen@desk-0181:~/examples/frontend$ cat .npmrc
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules). See
# https://github.com/aspect-build/rules_js/blob/7377f2d0387cc2a9251137929b1c53ccdb3fbcf0/docs/npm_import.md#npm_translate_lock
# documentation for more information.
hoist=false

public-hoist-pattern[]=@next/eslint-plugin-next*
public-hoist-pattern[]=eslint*
```

Contributor guide

Open the contributing guide

Research direction

Start with the public_hoist_packages configuration and the bazelbuild/examples/frontend MODULE.bazel entry referenced in the report. Run bazel build ... and inspect bazel-bin/node_modules, comparing the result with pnpm's public-hoist-pattern behavior. Done means the configured transitive package is hoisted into bazel-bin/node_modules as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.