flow-runtime icon indicating copy to clipboard operation
flow-runtime copied to clipboard

Use `require` instead of `import`

Open tnayuki opened this issue 7 years ago • 5 comments

Issuehunt badges

I just started to use flow-runtime & babel-plugin-flow-runtime, because these are very powerful packages.

This is a:

  • [ ] Bug Report
  • [x] Feature Request
  • [ ] Question
  • [ ] Other

Which concerns:

  • [ ] flow-runtime
  • [X] babel-plugin-flow-runtime
  • [ ] flow-runtime-validators
  • [ ] flow-runtime-mobx
  • [ ] flow-config-parser
  • [ ] The documentation website

What is the current behaviour?

Currently babel-plugin-flow-runtime generates code like this:

import t from 'flow-runtime';
const User = t.type('User', t.object(
  t.property('id', t.number()),
  t.property('name', t.string())
));

What is the expected behaviour?

My proposal is generating code like this:

const t = require('flow-runtime');
const User = t.type('User', t.object(
  t.property('id', t.number()),
  t.property('name', t.string())
));

If I can use flow-runtime & babel-plugin-flow-runtime without adding another plugin to transpile import, it becomes non-intrusive.


Which package versions are you using?


IssueHunt Summary

Backers (Total: $40.00)

Become a backer now!

Or submit a pull request to get the deposits!

Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

tnayuki avatar Jun 04 '18 01:06 tnayuki

I would say an option to choose between import and require is best. There are also cases where one would prefer to output import statements (e.g. for webpack)

jedwards1211 avatar Jun 04 '18 02:06 jedwards1211

I agree with an option is best. So I try to add the option and will make a PR.

tnayuki avatar Jun 05 '18 02:06 tnayuki

@tnayuki, I know this was a long time ago, but have you managed to make a fix? Even when I add another plugin those damn imports flow-runtime generates are not transpiled for me and I get a crash of my RN app...

terreb avatar Jul 10 '19 07:07 terreb

@issuehunt has funded $40.00 to this issue.


issuehunt-oss[bot] avatar Jul 24 '19 13:07 issuehunt-oss[bot]

@tnayuki you can : Save files with ES6 modules with .mjs extension and run it like: node --experimental-modules my-app.mjs

bu7ch avatar Aug 07 '19 10:08 bu7ch