Relay: [relay-compiler] eager es module mode does produce require calls

Created on 11 Feb 2021  路  5Comments  路  Source: facebook/relay

Despite using the eagerESModules option for the relay-compiler the generated code requires require calls.

The following function is responsible for this: https://github.com/facebook/relay/blob/ba9a3f031f8adc0f60bef603a76385433518cd90/packages/relay-compiler/codegen/createPrintRequireModuleDependency.js

I was able to create a workaround for this within the formatter function inside relay-compiler-language-typescript over here: https://github.com/relay-tools/relay-compiler-language-typescript/pull/269

My specific question is whether this can or should be addressed withing relay-compiler or whether it is better of being inside the language package?

Most helpful comment

All 5 comments

I think this belongs to relay-compiler

https://github.com/relay-tools/relay-compiler-language-typescript/pull/269 feels a bit hacky

It is indeed hacky, the real question is, whether this would be easy to solve within relay-compiler or whether it would require a lot of changes. Also afaik there is a new rust relay-compiler version coming...

Note: The relay-compiler flow formatter implementation prototype for es modules did the exact same: https://github.com/facebook/relay/pull/2841/files#diff-8258e3677c0534bd73d878b16093be514b2227f8972766d881bf903ff5f0e0d9R15-R27

However, the PR got succeeded by https://github.com/facebook/relay/pull/2781, which does not seem to have any logic for adjusting the require calls.

Maybe @TrySound and @vincentriemer could give some input?

When this "require" is added? I have non "requires" in my __generated__ modules.

Was this page helpful?
0 / 5 - 0 ratings