-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Bug: Flow error when using --eagerESModules
and @refetchable
#3404
Comments
mrtnzlml
changed the title
Flow error when using
Bug: Flow error when using Mar 12, 2021
--eagerESModules
and @refetchable
--eagerESModules
and @refetchable
mrtnzlml
added a commit
to adeira/universe
that referenced
this issue
Mar 12, 2021
This issue affects upstream as well, see: facebook/relay#3404 We have the advantage of having the generated output under control so I fixed it here for `@adeira/relay` and reported it to the upstream.
This was referenced Mar 12, 2021
kodiakhq bot
pushed a commit
to adeira/universe
that referenced
this issue
Mar 12, 2021
This issue affects upstream as well, see: facebook/relay#3404 We have the advantage of having the generated output under control so I fixed it here for `@adeira/relay` and reported it to the upstream.
adeira-github-bot
pushed a commit
to adeira/relay
that referenced
this issue
Mar 12, 2021
This issue affects upstream as well, see: facebook/relay#3404 We have the advantage of having the generated output under control so I fixed it here for `@adeira/relay` and reported it to the upstream. adeira-source-id: 079091984297d98698575e38e48da94aff601017
Using "require" with eagerESModules is not an option in any case. You can convert to esm like this. const javascript = require('relay-compiler/lib/language/javascript/RelayLanguagePluginJavaScript.js');
const { formatGeneratedModule } = require('relay-compiler');
module.exports = {
...
language: () => ({
...javascript(),
formatModule: options => {
// replace commonjs export
let formattedModule = formatGeneratedModule(options);
formattedModule = formattedModule.replace(
'module.exports = ',
'export default ',
);
// replace requires
let i = -1;
const paths = [];
formattedModule = formattedModule.replace(
/require\(('.+')\)/g,
(req, pathString) => {
i += 1;
paths.push(pathString);
return `__import__${i}`;
},
);
// add new imports
const imports = paths.map((p, i) => `import __import__${i} from ${p};\n`);
formattedModule = formattedModule.replace(
/'use strict';\n/,
`'use strict';\n\n${imports.join('')}`,
);
return formattedModule;
},
}),
}; |
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hola! 👋 This issue is for Relay 11.0.0. I created a reproducible demo here: https://github.com/mrtnzlml/bug-relay-useRefetchableFragment-flow
Specifically, the issue is with this line: https://github.com/mrtnzlml/bug-relay-useRefetchableFragment-flow/blob/53ee2bf03395037e72ad306f99df801ff4639491/__generated__/bugRelayUseRefetchableFragmentFlow.graphql.js#L36
Problem
Flow throws an error when generating artifacts with
--eagerESModules
and@refetchable
:Steps to reproduce
yarn install
yarn run relay-compiler --src=. --schema=schema.graphql --eagerESModules
yarn run flow
💥Possible solution
The artifact could be generated with
require(…).default
when using--eagerESModules
option like so:(no Flow errors)
The text was updated successfully, but these errors were encountered: