flow-node-esm
Like flow-node, but supports .mjs
/ES modules.
flow-node-esm ./script-with-flow-types.mjs
Requirements:
Notes
It's built using the experimental ESM loaders API and has only been tested to work in Node v16 LTS.
Due to a limitation of the loaders API, CommonJS modules cannot be transformed: you can import CJS files, but Flow types won't be stripped from them. However, you can still use Flow's comment syntax to add type annotations in these files.
flow-node-esm
can only be used for executing a file; a REPL is not implemented. Only one option is currently supported: -s
will strip Flow types using Sucrase instead of flow-remove-types. Sucrase is faster, but you may prefer sticking with the official parser if you're not worried about performance. (How much faster Sucrase is in your case is up to you to measure.)
The loader code here is based on the CoffeeScript loader example by Geoffrey Booth and contributors, with some modifications. Thanks for the helpful example!