gajus/flow-runtime

Do you want to work on this issue?

You can request for a bounty in order to promote it!


1 active bounty request

$40.00
Solve someone else's bounty request by clicking on it and completing the funding to earn additional credits

Use `require` instead of `import` #207

tnayuki posted onGitHub

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

<!-- Thanks for using flow-runtime! To help us address your issue quickly please provide as much information about the problem you're facing, or the feature you'd like adding. -->

This is a:

  • Bug Report
  • Feature Request
  • Question
  • Other

Which concerns:

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

What is the current behaviour?

<!-- If this is a bug report or question, please include example code wherever possible. If your code is private and you can't share it, please create a sanitized version which reproduces the issue. You may find the online demo useful for this: https://codemix.github.io/flow-runtime/#/try NOTE: It is extremely difficult to fix bugs without examples! -->

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?

<!-- Please describe what you'd expect to happen under these circumstances. If you are describing a bug in the babel plugin, please indicate the output you'd expect it to produce. -->

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?

<!-- If this is a bug, which version(s) of the affected package(s) are you using? If you're describing a bug specific to an environment, like a certain browser or node version, please include that information here too. -->


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)

posted by jedwards1211 almost 7 years ago

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

posted by tnayuki almost 7 years ago

@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...

posted by terreb over 5 years ago

@issuehunt has funded $40.00 to this issue.


posted by issuehunt-app[bot] over 5 years ago

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

posted by bu7ch over 5 years ago

Fund this Issue

$40.00
Funded
Only logged in users can fund an issue

Pull requests

Recent activities

issuehunt funded 40.00 for gajus/flow-runtime# 207
over 5 years ago