I remember when I started coding I would see some js files using require() to import modules and other files using import. This always confused me ...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks for this article. I run into lots of nasty messages when I import commonJS libraries into my Angular (client) code. It works fine, but I'm sure I'm importing more than necessary ... and the ability to generate PDFs is too good a feature to give up.
You're welcome, glad you enjoyed it!
I also write a weekly newsletter for developers, check it out if you'd like! travislramos.beehiiv.com/subscribe
Always good to learn what goes on under the hood when using require vs. import, thanks for the great post!
You're welcome, I'm glad you enjoyed it!
Why do we need to use require for dynamic or run time loading?
That's a great question.
So the way import works is that it runs at the start of a script since it is statically analyzed.
When you use require(), you can put it in a condition and only load that module based on a specific condition. Since require() can be invoked at any point in your code, this allows it to be dynamic.
Also, if you found this article helpful, I write a weekly newsletter for devs to help them level up and learn along with me! You can check it out here: travislramos.beehiiv.com/subscribe
It's good article
Thank you, if you'd like to see more content similar to this, give my newsletter a follow! I send it out weekly to over 100 developers like you!
travislramos.beehiiv.com/subscribe
Cool
Great! Thanks for sharing!
No problem, glad you enjoyed it!
If you'd like more content similar to this, I write a weekly newsletter that I send out to developers. You can find it here: travislramos.beehiiv.com/subscribe
Damn man, i was just facing confusion between these two just moments ago. Thank you very much
You're welcome, I'm glad it helped!
I also write a weekly newsletter with similar content and other cool things I think would be helpful for other develoeprs. Check it out if you'd like! travislramos.beehiiv.com/subscribe
Thank you for sharing!
Yea, no problem! If you found it useful, I also send out a weekly newsletter with content similar to this, plus any useful links I've found throughout the week that I think others would find useful as well. Check it out here: travislramos.beehiiv.com/subscribe
Thank you, it cleared up a lot of doubts about import vs require
You're welcome, I'm glad I could help!
If you'd like to receive similar content to your email, I write a weekly newsletter that other developers find useful! Check it out: travislramos.beehiiv.com/subscribe