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

babel-plugin-relay bug: eagerEsModules: true only works with single-project Relay configs. #4909

Open
tomfuhrer opened this issue Feb 10, 2025 · 3 comments · May be fixed by #4934
Open

babel-plugin-relay bug: eagerEsModules: true only works with single-project Relay configs. #4909

tomfuhrer opened this issue Feb 10, 2025 · 3 comments · May be fixed by #4934

Comments

@tomfuhrer
Copy link

tomfuhrer commented Feb 10, 2025

Summary of the bug

When "eagerEsModules": true is set in a multi-project Relay config, babel-plugin-relay transforms graphql tagged templates into require calls, like this:

var _MeQuery;
var MeQuery =
  _MeQuery !== void 0
    ? _MeQuery
    : ((_MeQuery = require("./__generated__/MeQuery.graphql")),
      _MeQuery.hash &&
        _MeQuery.hash !== "bce9f1cc4614c3f306814d78c53b009b" &&
        console.error(
          "The definition of 'MeQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."
        ),
      _MeQuery);

Expected behavior

Just like it does with a single-project Relay config, babel-plugin-relay should transform graphql tagged templates into import declarations when "eagerEsModules": true is set, like this:

import _MeQuery from "../__generated__/MeQuery.graphql";
var MeQuery =
  (_MeQuery.hash &&
    _MeQuery.hash !== "bce9f1cc4614c3f306814d78c53b009b" &&
    console.error(
      "The definition of 'MeQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."
    ),
  _MeQuery);

Reproducing the bug

I created a reduced test case to demonstrate this behavior. If you want to reproduce the bug yourself, you can clone the repo, run the build commands, and compare the output. The repo also includes the dist files (one each for single and multi-project configs), so if you want to take my word for It, you can just compare the outputs on GitHub. More detail in the README.

@captbaritone
Copy link
Contributor

Thanks for catching this! Do you want to work on PR to fix?

@tomfuhrer
Copy link
Author

tomfuhrer commented Feb 11, 2025

I mean, yeah. It will take me a minute, though, since I'm enough of a beginner to have lots of stupid questions still. But I've been working on it, and I can open a PR once I figure it out.

@tomfuhrer tomfuhrer linked a pull request Mar 6, 2025 that will close this issue
@tomfuhrer
Copy link
Author

I think I got it. I opened #4934.

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

Successfully merging a pull request may close this issue.

3 participants