import.meta is a stage 3 proposal that has shipped in Chrome, Firefox, and Node 10. Flow should be able to parse this syntax.
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBLAtgBzgJwBcA6LAU0IENiBXfGAbiA
Implemented in #6958.
Friendly ping on that PR. I know some folks were interested in this and
wouldn鈥檛 want the diff to go stale.
We didn't get a response from your previously friendly ping @wchargin, so I'm pinging again hoping we are gonna get some response now :)
import.meta.url is the official way to have __dirname in ESM node implementation. ES6 Module support is very strict in node.
https://nodejs.org/docs/latest/api/esm.html
We can't migrate to modules while flow is not supporting it (flow-remove-types makes an error on this syntax too). Or we have to get around the __dirname variable.
It's not implemeted yet( Though import.meta is living standard already.
I cannot use flow because use of import.meta breaks flow parsing of the entire source file from that point forward...
Yes, I am using import.meta.url to obtain __dirname in node scripts.
I use this ugly workaround to make both Flow and Node.js happy:
// $FlowFixMe
let __filename /*: string */ = url.fileURLToPath(import /*:: ("") */.meta.url);
I don't know if this works with flow-removes-types or Babel, though.
Most helpful comment
I use this ugly workaround to make both Flow and Node.js happy:
I don't know if this works with flow-removes-types or Babel, though.