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.

Prefer `import` over `require`

See original GitHub issue

I recommend sticking with import rather than require as much as possible to keep the types.

require does have it’s place for sure though. Such as, guarding with an if statement or intentionally dodging bad types in a 3rd party lib. Unlike require, import gets hoisted so it’s not as flexible, but checks that huge static analysis checkbox!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
skellockcommented, Jan 11, 2018

We’ve spent the last 10 years (and probably the next 5) reinventing something that’s been solved for 30 years. Static & dynamic library loading.

I love learning, so I’m not bitter. I’m just unproductive.

0reactions
infinitered-circlecicommented, Dec 7, 2018

🎉 This issue has been resolved in version 0.22.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

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
Import is always run at the very beginning of the file and can't be run conditionally. On the other hand, require can be...
Read more >
node.js - The difference between "require(x)" and "import x"
Loading is synchronous(step by step) for require on the other hand import can be asynchronous(without waiting for previous import) so it can perform...
Read more >
Require vs. Import in JavaScript - Stack Diary
In general, import is preferred over require because it is a more modern and flexible syntax, and it will eventually replace require in...
Read more >
Compare require() vs import() in JavaScript | by Sumeet Bhalla
Usually, we call the import() or require() statements at the beginning of a file. But you can call require() from anywhere in the...
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