🐞 bug report
Affected Rule
The issue is caused by the rule: yarn_install, npm_install
Is this a regression?
No, just an issue with exports_directories_only.
Description
Installing graphql-codegen with exports_directories_only=True causes code generation to fail, with an error message about instanceof checks failing due to duplicate graphQL modules. The failure mode is similar to this issue. I imagine this could affect other tools besides just GraphQL Codegen.
🔬 Minimal Reproduction
https://github.com/ptsteadman/graphql-codegen-repro
Command to run bazel build :gen
The most recent commit adds exports_directories_only=True and GraphQL codegen fails with error messages about failed instanceof checks. Previous commit (without exports_directories_only) succeeds.
🔥 Exception or Error
...
DEBUG: /private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/external/build_bazel_rules_nodejs/internal/linker/link_node_modules.bzl:19:14: [link_node_modules.bzl] No LinkablePackageInfo for @npm//@graphql-codegen/typescript:typescript
INFO: Analyzed target //:gen (0 packages loaded, 2045 targets configured).
INFO: Found 1 target...
ERROR: /Users/patrick.steadman/ptsteadman/graphql-codegen-repro/BUILD.bazel:9:16: Action types.ts failed: (Exit 1): graphql-codegen.sh failed: error executing command bazel-out/host/bin/external/npm/@graphql-codegen/cli/bin/graphql-codegen.sh --config bazel-out/darwin-fastbuild/bin/config-codegen.yml ... (remaining 1 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
[link_node_modules.js] manifest file: bazel-out/darwin-fastbuild/bin/_gen.module_mappings.json
[link_node_modules.js] manifest contents: {
"workspace": "graphql_codegen_repo",
"bin": "bazel-out/darwin-fastbuild/bin",
"roots": {
"": "npm"
},
"module_sets": {}
}
[link_node_modules.js] startCwd: /private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo
[link_node_modules.js] execroot: /private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo
[link_node_modules.js] isExecroot: true
[link_node_modules.js] isBazelRun: false
[link_node_modules.js] resolved npm external workspace node modules path to /private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/external/npm/node_modules
[link_node_modules.js] creating symlink node_modules -> /private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/external/npm/node_modules
[link_node_modules.js] creating symlink /private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/bazel-out/host/bin/external/npm/@graphql-codegen/cli/bin/graphql-codegen.sh.runfiles/graphql_codegen_repo/node_modules -> /private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/external/npm/node_modules
BAZEL_NODE_MODULES_ROOTS=:npm
BAZEL_PATCH_ROOTS=/private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo,/private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/node_modules,/private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/bazel-out/host/bin/external/npm/@graphql-codegen/cli/bin/graphql-codegen.sh.runfiles,/private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/bazel-out/host/bin/external/npm/@graphql-codegen/cli/bin/graphql-codegen.sh.runfiles/graphql_codegen_repo/node_modules
bazel node patches enabled. roots: /private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo,/private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/node_modules,/private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/bazel-out/host/bin/external/npm/@graphql-codegen/cli/bin/graphql-codegen.sh.runfiles,/private/var/tmp/_bazel_patrick.steadman/eb0c3c53e497b1e29bb170c55a02ab01/sandbox/darwin-sandbox/12/execroot/graphql_codegen_repo/bazel-out/host/bin/external/npm/@graphql-codegen/cli/bin/graphql-codegen.sh.runfiles/graphql_codegen_repo/node_modules symlinks in these directories will not escape
Something went wrong
[18:56:56] Parse configuration [started]
[18:56:56] Parse configuration [completed]
[18:56:56] Generate outputs [started]
[18:56:56] Generate bazel-out/darwin-fastbuild/bin/types.ts [started]
[18:56:56] Load GraphQL schemas [started]
[18:56:56] Load GraphQL schemas [completed]
[18:56:56] Load GraphQL documents [started]
[18:56:56] Load GraphQL documents [completed]
[18:56:56] Generate [started]
[18:56:56] Generate [failed]
[18:56:56] → Cannot use GraphQLObjectType "Book" from another module or realm.
Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.
https://yarnpkg.com/en/docs/selective-version-resolutions
Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
[18:56:56] Generate bazel-out/darwin-fastbuild/bin/types.ts [failed]
[18:56:56] → Cannot use GraphQLObjectType "Book" from another module or realm.
...
🌍 Your Environment
Operating System:
Output of bazel version:
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.)
4.6.1 (seems to affect previous versions as well)
Anything else relevant?
I tried running the codegen via npm_package_bin and had the same issue.
🐞 bug report
Affected Rule
The issue is caused by the rule: yarn_install, npm_install
Is this a regression?
No, just an issue with
exports_directories_only.Description
Installing graphql-codegen with
exports_directories_only=Truecauses code generation to fail, with an error message aboutinstanceofchecks failing due to duplicate graphQL modules. The failure mode is similar to this issue. I imagine this could affect other tools besides just GraphQL Codegen.🔬 Minimal Reproduction
https://github.com/ptsteadman/graphql-codegen-repro
Command to run
bazel build :genThe most recent commit adds
exports_directories_only=Trueand GraphQL codegen fails with error messages about failedinstanceofchecks. Previous commit (without exports_directories_only) succeeds.🔥 Exception or Error
🌍 Your Environment
Operating System:
Output of
bazel version:Rules_nodejs version:
(Please check that you have matching versions between WORKSPACE file and
@bazel/*npm packages.)Anything else relevant?
I tried running the codegen via
npm_package_binand had the same issue.