Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL Codegen Fails When Installed via exports_directories_only=True #3264

Closed
ptsteadman opened this issue Jan 19, 2022 · 4 comments · Fixed by #3380
Closed

GraphQL Codegen Fails When Installed via exports_directories_only=True #3264

ptsteadman opened this issue Jan 19, 2022 · 4 comments · Fixed by #3380
Assignees
Labels

Comments

@ptsteadman
Copy link

ptsteadman commented Jan 19, 2022

🐞 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:

  
   OSX on M1 arm processor
  

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.

@m0ar
Copy link

m0ar commented Mar 8, 2022

This affects us greatly as well since we hit severe slowdowns in CI by having to use exports_directories_only = False. Do you have any updates (or workarounds) in sight @gregmagolan ? 😊

@thesayyn thesayyn self-assigned this Mar 29, 2022
@thesayyn
Copy link
Collaborator

adding --bazel_run_from_execroot to args is the workaround

eg

graphql_codegen(
    name = "gen",
    outs = ["types.ts"],
    args = [
        "--errors-only",
        "--config",
        "$(location :config)",
        "--bazel_run_from_execroot"
    ]
)

@patrick-steadman
Copy link

Exciting, I will try this out! And great that there's a PR as well!

@ptsteadman
Copy link
Author

Confirmed that the workaround works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants