Skip to content

Loading from multiple node_modules with version > 4.4.1 #3067

@duarten

Description

@duarten

🐞 bug report

Affected Rule

nodejs_binary / nodejs_test

Is this a regression?

Yes, 4.4.1 works fine, but 4.4.2 and 4.4.3 are broken. This is likely related to the linker refactor.

Description

When a package is symlinked under node_modules due to, for example, the packge_name attribute of js_library, then node modules will be loaded from a different directory.

I noticed this with react, which complains when multiple instances are loaded.

We can see the problem from the following (edited) stack trace:

 <snip> at useMemo (node_modules/repro/node_modules/react/cjs/react.development.js:1531:20) at Component (../component/component.tsx:4:12) <snip> at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) <snip> at runCLI (node_modules/@jest/core/build/cli/index.js:173:3) 

Notice how we first load react from node_modules/react-dom, and later from node_modules/repro/node_modules.

The component package contains the following rule:

js_library( name = "component", package_name = "repro/component", visibility = ["//visibility:public"], deps = ["component-ts"], )

Omitting the workspace name (repro) from the package_name seems to solve the problem (i.e., changing it to "component" or "blah/component").

🔬 Minimal Reproduction

I committed a reproduction here.

🔥 Exception or Error

In this case, react complains and the test fails.

🌍 Your Environment

Operating System:

  macOS  

Output of bazel version:

  4.2.1  

Rules_nodejs version:

  4.4.3  

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions