Prefer `import` over `require`
See original GitHub issueI 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:
- Created 6 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
🎉 This issue has been resolved in version 0.22.1 🎉
The release is available on:
Your semantic-release bot 📦🚀