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

Do not strip flow import type declarations #12669

Closed
djvern opened this issue Jan 21, 2021 · 6 comments
Closed

Do not strip flow import type declarations #12669

djvern opened this issue Jan 21, 2021 · 6 comments
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@djvern
Copy link

djvern commented Jan 21, 2021

The latest version of Babel 7 strips out flow import type declarations by default. They used to be included with earlier versions of Babel 7 and 6. Whilst it makes sense to remove them, is there an easy way to keep them and treat them as regular imports, as the app I'm working on uses flow-runtime and relies on the types to work.

Is there an existing plugin that can do this, or do I need to write my own? At the moment I'm replacing import type with import as a build step before running babel, but if feels like there should be a way to do it all within Babel.

@babel-bot
Copy link
Collaborator

Hey @djvern! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@JLHwung
Copy link
Contributor

JLHwung commented Jan 21, 2021

You can skip the flow transform by replacing @babel/preset-flow to @babel/plugin-syntax-flow, so Babel will leave the flow syntax as-is. Then you can pass the generated code to flow-runtime.

@djvern
Copy link
Author

djvern commented Jan 25, 2021

Ah, I tried that but import type declarations are still being stripped out. Is this just a default setting in Babel now? If so, how can I override it?

@nicolo-ribaudo
Copy link
Member

Babel by default doesn't transform your code, you are unknowingly enabling the flow transform somewhere.

You can post the output of BABEL_SHOW_CONFIG_FOR (use your build command instead of npm start) if you need help figuring out where it's enabled.

@nicolo-ribaudo
Copy link
Member

Closing since this was a configuration problem. If you still need help feel free to ping.

@djvern
Copy link
Author

djvern commented Feb 21, 2021

@nicolo-ribaudo thanks for the info - after a bit more investigating I realised the issue was with flow-runtime and the plugin babel-plugin-flow-runtime. There's a fix in the latest version which has resolved the issue if it helps anyone else: gajus/flow-runtime#254

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants