Relay: babel-plugin-relay and relay-compiler are not compatible with ES6 modules

Created on 13 May 2018  路  9Comments  路  Source: facebook/relay

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.

All 9 comments

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 Thanks, but I'm already using this rollup plugin after the rollup babel plugin and it's not replacing the require-calls.

@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.

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

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.

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.

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

Yes, enable eagerESModules option in relay config.

Was this page helpful?
0 / 5 - 0 ratings