unjs / jiti

Runtime Typescript and ESM support for Node.js
MIT License
1.49k stars 52 forks source link

fix: use internal cached modules only if loaded #245

Closed pi0 closed 4 weeks ago

pi0 commented 4 weeks ago

Update: reverted in v1.21.5 as hotfix for circular dep support (#246) and added back in https://github.com/unjs/jiti/pull/247


This PR fixes a race condition that when importing the same id in parallel from several places (using await import()) the jiti was picking the (still) evaluating module without valid exports.


Context: Found it while investigating https://github.com/nuxt/nuxt/pull/27479, however this issue is just likely simply revealed with other perf improvements that increased the chance of this race.