rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

`npm_package_bin` doesn't pick up transitive npm deps.

Open charlesoconor opened this issue 2 years ago • 0 comments

🐞 bug report

Affected Rule

npm_package_bin seems like it isn't pulling in transitive npm dependencies well data. I was assuming they should be coming fromExternalNpmPackageInfo.

https://github.com/bazelbuild/rules_nodejs/blob/stable/internal/node/npm_package_bin.bzl#L38

Is this a regression?

I haven't seen this work in the previous version of nodejs_rules

Description

All the current examples of using webpack pass @npm//:node_modules to dependencies. This works correctly when generating an output bundle. I was hoping to use a smaller subset of node_module to speed up the builds. I had assumed that all the data defined on ts_project targets would be available for webpack to run over to create the bundle.

The transitive data are working correctly for node_binary and node_tests.

🔬 Minimal Reproduction

I've modified the example in examples/react_webpack to create a simple repro.

https://github.com/charlesoconor/rules_nodejs/pull/1/files

🔥 Exception or Error


Use --sandbox_debug to see verbose messages from the sandbox
Hash: ebb874c85885aa797546
Version: webpack 4.41.0
Time: 229ms
Built at: 05/23/2022 4:32:47 PM
 1 asset
Entrypoint main = app.bundle.js
[0] ./bazel-out/darwin-fastbuild/bin/index.js 266 bytes {0} [built]
[1] ./bazel-out/darwin-fastbuild/bin/styles.css 426 bytes {0} [built]
[2] ./node_modules/css-loader/dist/cjs.js??ref--4-1!./bazel-out/darwin-fastbuild/bin/styles.css 255 bytes {0} [built]
    + 2 hidden modules

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in ./bazel-out/darwin-fastbuild/bin/index.js
Module not found: Error: Can't resolve 'react' in '/private/var/tmp/_bazel_charlieoconor/f17732fb2ac749381fe763108756df92/sandbox/darwin-sandbox/1824/execroot/react_webpack/bazel-out/darwin-fastbuild/bin'
 @ ./bazel-out/darwin-fastbuild/bin/index.js 3:12-28

ERROR in ./bazel-out/darwin-fastbuild/bin/index.js
Module not found: Error: Can't resolve 'react-dom' in '/private/var/tmp/_bazel_charlieoconor/f17732fb2ac749381fe763108756df92/sandbox/darwin-sandbox/1824/execroot/react_webpack/bazel-out/darwin-fastbuild/bin'
 @ ./bazel-out/darwin-fastbuild/bin/index.js 4:15-35
Target //:bundle failed to build

Got if running by pulling run files from DefaultInfo here https://github.com/bazelbuild/rules_nodejs/blob/stable/internal/node/npm_package_bin.bzl#L47. eg.


        if DefaultInfo in d:
            inputs_depsets.append(d[DefaultInfo].data_runfiles.files)

🌍 Your Environment

Operating System: Tried this on linux and mac

  
Ubuntu 20
Mac osx Big Sur
  

Output of bazel version:

  
5.0.0
  

Rules_nodejs version:

  
5.5.0
  

Just finished my upgrade to 5.5.0 and overall everything seems to be building much faster. I think getting webpack to build correctly is the last step.

charlesoconor avatar May 23 '22 20:05 charlesoconor