Coder Social home page Coder Social logo

rules_nodejs-issue-3479's Introduction

rules_nodejs - Issue #3479

This is a replication of a bug in rules_nodejs where the package_path directive seems to only work on references within the same repository, and does not work when the same library is referenced externally.

In this repo, there are two workspaces, ext_ws and main_ws. In ext_ws a simple js_library is defined and can be imported by nodejs_binary targets within the workspace.

However, this fails to work when the same library is references from a nodejs_library in another workspace, i.e. from main_ws. Note that this target contains identical source code and BUILD definition to the target in ext_ws that works.

We can see this with the following commands:

$ cd ext_ws && bazel run //:bin

INFO: Analyzed target //:bin (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:bin up-to-date:
  bazel-bin/bin.sh
  bazel-bin/bin_loader.cjs
  bazel-bin/bin_require_patch.cjs
INFO: Elapsed time: 0.105s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Hello world? Hello world.

$ cd main_ws && bazel run //:bin

INFO: Analyzed target //:bin (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:bin up-to-date:
  bazel-bin/bin.sh
  bazel-bin/bin_loader.cjs
  bazel-bin/bin_require_patch.cjs
INFO: Elapsed time: 0.245s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Error: Cannot find module '@ext/ws/lib'
Require stack:
- /home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/bin.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (bin.js:1:13)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

If we compare the execroots, we see that a node_modules entry is populated in the former case, but only an empty root directory is created in the latter:

# Execroot from a run of `@ext_ws//:bin
$ find /home/pras/.cache/bazel/_bazel_pras/92b5a6b34dd09a1331f2af4192a3d949/execroot/ | grep @ext
/home/pras/.cache/bazel/_bazel_pras/92b5a6b34dd09a1331f2af4192a3d949/execroot/ext_ws/node_modules/@ext
/home/pras/.cache/bazel/_bazel_pras/92b5a6b34dd09a1331f2af4192a3d949/execroot/ext_ws/node_modules/@ext/ws
# Execroot from a run of `@main_ws//:bin
$ find /home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/ | grep @ext
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/node_modules/@ext

Furthermore, if we include a source file from ext_ws in a js_library, defined in main_ws, it will be omitted from the build.

cd main_ws && bazel run //:bin2

INFO: Analyzed target //:bin2 (2 packages loaded, 4 targets configured).
INFO: Found 1 target...
Target //:bin2 up-to-date:
  bazel-bin/bin2.sh
  bazel-bin/bin2_loader.cjs
  bazel-bin/bin2_require_patch.cjs
INFO: Elapsed time: 0.209s, Critical Path: 0.01s
INFO: 7 processes: 7 internal.
INFO: Build completed successfully, 7 total actions
INFO: Build completed successfully, 7 total actions
Error: Cannot find module '@ext/ws/lib'
Require stack:
- /home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin2.sh.runfiles/main_ws/bin.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (bin.js:1:13)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

If we inspect the execroot here, we can see that the module is created, but does not include source files from the external repository.

# Execroot from a run of `@main_ws//:bin2
$ find -L /home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/ | grep node_modules
find: File system loop detected; ‘/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules/@ext/ws/bin.sh.runfiles’ is part of the same file system loop as ‘/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/’.
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules/@ext
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules/@ext/ws
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules/@ext/ws/bin_loader.cjs
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules/@ext/ws/bin_require_patch.cjs
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules/@ext/ws/bin.sh
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules/@ext/ws/_bin.module_mappings.json
/home/pras/.cache/bazel/_bazel_pras/df2aff05c573141092662ae5db828664/execroot/main_ws/bazel-out/k8-fastbuild/bin/bin.sh.runfiles/main_ws/node_modules/@ext/ws/bin.sh.runfiles_manifest

rules_nodejs-issue-3479's People

Contributors

psigen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.