question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use `require` instead of `import`

See original GitHub issue

Issuehunt badges

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

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?

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jedwards1211commented, Jun 4, 2018

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)

0reactions
bu7chcommented, Aug 7, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Difference between node.js require and ES6 import and export
Require is Non-lexical, it stays where they have put the file. Import is lexical, it gets sorted to the top of the file....
Read more >
Using Node.js require vs. ES6 import/export - Stack Overflow
See when we require the component in asynchronous way, then we use import it in some async manner as in const variable using...
Read more >
JavaScript Require vs. Import - Bits and Pieces
1. Require statements can be called anywhere in the code · 2. Require can be called conditionally · 3. Import statements are asynchronous...
Read more >
Require vs Import | Know The 4 Most Amazing Comparisons
Require is more of dynamic analysis, and import is more of static analysis. · Require Throws error at runtime and Import throws error...
Read more >
Compare require() vs import() in JavaScript | by Sumeet Bhalla
require () statements are called synchronously one by one whereas import() are called asynchronously and they are known to perform well compared ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found