facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.41k stars 1.83k forks source link

babel-plugin-relay and relay-compiler are not compatible with ES6 modules #2445

Open bahador opened 6 years ago

bahador commented 6 years ago

The output of using babel-plugin-relay uses require, and the output of relay-compiler uses module.exports.

I'd like to request that there be an option to use ES6 import statements instead of require and that relay-compiler output ES6 modules.

TIA.

kortac commented 6 years ago

Is there a workaround for this? I'm using rollup to bundle my package and babel-plugin-relay breaks the bundle as it adds require-calls to the code.

TrySound commented 6 years ago

@SpaceHeroGuide https://github.com/rollup/rollup-plugin-commonjs

kortac commented 6 years ago

@TrySound Thanks, but I'm already using this rollup plugin after the rollup babel plugin and it's not replacing the require-calls.

bahador commented 6 years ago

@SpaceHeroGuide is correct. This is not an issue that rollup-plugin-commonjs can solve. One solution would be to have a flag to output ES6 modules instead of using require and module.exports. I looked into fixing this myself and submitting a PR, but this isn't my area of expertise.

TrySound commented 6 years ago

Could you provide reproducing repo where commonjs plugin doesn't work?

alloy commented 6 years ago

My language plugin PR also happens to fix (part of) this situation, but the overall scope of that PR is a bit larger https://github.com/facebook/relay/pull/2293

Specifically what it does is look for a default export. The exports from the artifacts, though, are left up to the specific language plugin to define, which in the case of JS/Flow would remain the same as currently the case is.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

theseyi commented 3 years ago

This seems related to https://github.com/facebook/relay/issues/2706 which is also as yet unresolved. Has the community found a sustainable solution to this yet? I'm using rollupjs and ran into this yesterday as well

TrySound commented 3 years ago

Yes, enable eagerESModules option in relay config.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.