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

Using flow-remove-types will fail when using ES Modules #8622

Open
callumgare opened this issue Mar 22, 2021 · 3 comments
Open

Using flow-remove-types will fail when using ES Modules #8622

callumgare opened this issue Mar 22, 2021 · 3 comments

Comments

@callumgare
Copy link

If flow-remove-types is run in a repo where package.json contains "type": "module" then it will fail. This occurs with the latest version of flow-remove-types (2.147.0) and flow (0.147.0). I've thrown together an example repo for reproduction: https://github.com/callumgare/example-flow-node-es-modules-fail

When running npx flow-remove-types index.js in the above repo with node 14 under ubuntu I get:

file:///home/callumgare/repos/flow-node-test/index.js:2
function main(val: string) {
                 ^

SyntaxError: Unexpected token ':'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:141:18)
    at async link (internal/modules/esm/module_job.js:42:21)
@geraintwhite
Copy link

I get the same issue when using flow-node to execute files.

I've had to fall back to combining require for values and import for types.

@callumgare
Copy link
Author

I encountered a similar issue with babel-node and I'm guessing that's the same thing going on here.

@mroch
Copy link
Contributor

mroch commented Oct 4, 2021

flow-remove-types works by hooking into require (via pirates), so it only works with CJS. to work with ESM, we need to use node's loaders which are still experimental and say "Note: The loaders API is being redesigned. This hook may disappear or its signature may change. Do not rely on the API described below"

So I think we'll wait until it's stable so we don't cause ourselves issues in the future. We decided to go back to require for flow-dev-tools until native ESM fully works in node. see 50ee686

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants