rules_nodejs
rules_nodejs copied to clipboard
Regression in linker behavior changes behavior of instanceof operator
🐞 bug report
Is this a regression?
Yes, most likely, the previous version in which this bug was not present was: rules_nodejs 4.4.1
By applying patches that revert changes after this commit I've verified that the change in instanceof
behavior began there. Trying other rules_nodejs versions higher than 4.4.2 also exhibit the same behavior.
Description
After upgrading to rules_nodejs
version 4.4.3 or above, a number of our jest tests began to fail due to changes in the behavior of instanceof
checks of imported classes like so:
expect(received).toBeInstanceOf(expected)
Expected constructor: TokenExpiredError
Received constructor: TokenExpiredError
The issue only occurs when classes are imported from a different target (file or module). I'm not sure of the root cause, but in looking into the VERBOSE_LOGS output, I noticed a change the linker behavior changed from 4.4.1 to 4.4.2 that suggests problems with symlinks (directories being symlinked to themselves):
4.4.1
[link_node_modules.js] resolved npm workspace node modules path to /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1245/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/npm/node_modules
[link_node_modules.js] creating symlink node_modules -> /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1245/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/npm/node_modules
[link_node_modules.js] modules for package path '':
{
"monorepo": "bazel-out/darwin-fastbuild/bin"
}
[link_node_modules.js] mapping hierarchy for package path '':
[{"name":"monorepo","link":"bazel-out/darwin-fastbuild/bin"}]
[link_node_modules.js] creating symlink node_modules/monorepo -> /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1245/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/monorepo/
4.4.3 and above:
[link_node_modules.js] resolved npm external workspace node modules path to /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1049/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/npm/node_modules
[link_node_modules.js] creating symlink node_modules -> /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1049/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/npm/node_modules
[link_node_modules.js] creating symlink /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1049/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/monorepo/node_modules -> /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1049/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/npm/node_modules
[link_node_modules.js] creating symlink /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1049/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/monorepo/node_modules -> /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1049/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/npm/node_modules
[link_node_modules.js] modules for package path '':
{
"monorepo": "bazel-out/darwin-fastbuild/bin"
}
[link_node_modules.js] mapping hierarchy for package path '':
[{"name":"monorepo","link":"bazel-out/darwin-fastbuild/bin"}]
[link_node_modules.js] creating symlink node_modules/monorepo -> /private/var/tmp/_bazel_patrick.steadman/b224a9219bba4062995e170e51484c48/sandbox/darwin-sandbox/1049/execroot/monorepo/bazel-out/darwin-fastbuild/bin/src/typescript/clientapi/resolvers/client-information/phone_resolvers_test.sh.runfiles/monorepo/
🔬 Minimal Reproduction
Unfortunately I have not yet had time to create a minimal reproduction, the issue is likely related to a specific combination of our tsconfig, jest config, and ts_library
usage. I will work towards making a reproduction but figured I'd open an issue now in case others are having similar issues.
🌍 Your Environment
Operating System:
OSX (also occurs on Ubuntu Linux)
Output of bazel version
:
Starting local Bazel server and connecting to it...
Build label: 4.2.1
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Aug 30 15:24:28 2021 (1630337068)
Build timestamp: 1630337068
Build timestamp as int: 1630337068
Rules_nodejs version:
(Please check that you have matching versions between WORKSPACE file and @bazel/*
npm packages.)
WORKSPACE: 4.4.2
@bazel/typescript 4.4.0
Thank you!