sindresorhus / import-fresh

Import a module while bypassing the cache
MIT License
284 stars 25 forks source link

feat: Support Dynamic Import in Webpack Context #27

Open CHC383 opened 4 months ago

CHC383 commented 4 months ago

close https://github.com/sindresorhus/import-fresh/issues/21

Credit: Thanks @jeremiegirault for proposing the changes in https://github.com/sindresorhus/import-fresh/issues/21

Description

Webpack will try to bundle modules during compile time and replace the original require, so using require directly in the Webpack context to load configs could result in MODULE_NOT_FOUND error. Switching to __non_webpack_require__ to use plain require while in the Webpack environment.

About __non_webpack_require__:

Try to solve issues like:

Test

npm run test

abuaboud commented 4 months ago

I think this is exactly what I am looking for, spent at least 8 hours debugging this :D I suspected it's worker threads but then found it's webpack!

You are hero! going to try it now!

EDIT: It did work! THANK YOU!