standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

How to use this package together with flow-remove-types? #842

Closed bensampaio closed 4 years ago

bensampaio commented 4 years ago

I am trying to use flow-remove-types to remove types from node scripts before running them. I tried the following: node -r esm -r flow-remove-types/register index.mjs. This fails at type annotations. Is this an issue with this package or with flow-remove-types?

TrySound commented 4 years ago

Does this work for you?

node -r flow-remove-types/register -r esm index.mjs
bensampaio commented 4 years ago

No, I still get this error:

file:///typeHelper.mjs
export const isArray = (value: any): boolean %checks => {
                             ^

SyntaxError: Invalid or unexpected token
TrySound commented 4 years ago

Does it work with .js?

bensampaio commented 4 years ago

Yes :o If I change all imported files to js then it works. Is this an issue with esm or with flow-remove-types? And do you know what's missing? Thanks!

bensampaio commented 4 years ago

Ping! @TrySound why did you ask if it only works with .js? I still need a solution since changing all files to .js in the repo I am working on is not really realistic.

TrySound commented 4 years ago

Both tools support mjs. I don't know what is the problem. But using mjs for source code was not a good idea :)

bensampaio commented 4 years ago

I couldn't figure this out so I ended up changing the extensions of my files to .js and I switched from esm to @babel/node which fits my use case a lot better anyway.

jdalton commented 4 years ago

The docs state that .mjs is restricted (no esm options or extra functionality extend to it). Since ES module support was experimental in Node the functionality we extend to .js is not covered by .mjs.