question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not strip flow import type declarations

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
djverncommented, 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: https://github.com/gajus/flow-runtime/issues/254

1reaction
nicolo-ribaudocommented, Jan 25, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flowtype – how to export and import types? - Stack Overflow
If I fail to put // @flow in Module A , the compiler treats NumberAlias as any , and fails to ... import...
Read more >
Utility Types - JavaScript. Flow
The resulting type from this operation will be an object type containing A 's own properties that are not own properties in B...
Read more >
babel/plugin-transform-flow-strip-types
Setting this to true will only strip annotations and declarations from files that contain the // @flow directive. It will also throw errors...
Read more >
Documentation - TypeScript 3.8
import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there's no remnant of...
Read more >
Migrating 500k lines of Flow code to TypeScript - Medium
A look into migrating a large codebase from one type checking tool to another. Foreword. This article is not meant to justify why...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found