GoogleChromeLabs / dynamic-import-polyfill

A fast, tiny polyfill for dynamic import() that works in all module-supporting browsers
MIT License
320 stars 13 forks source link

Dynamic imports are not resolved relative to importing module #8

Open LarsDenBakker opened 4 years ago

LarsDenBakker commented 4 years ago

Let's say I have a module on a CDN: https://unpkg.com/lit-element/lit-element.js and from this module I do a dynamic import: import('./foo.js')

With native dynamic imports it will import https://unpkg.com/lit-element/foo.js. With this polyfill it will import window.location + moduleDirectory + 'foo.js' which is incorrect.

Instead the import should be resolved relative to the importing module, the polyfill could accept a second (optional) parameter for that. This does require bundlers to implement this as well, I filed https://github.com/rollup/rollup/issues/3444 on rollup side for that.

ghattrell commented 3 years ago

Hey @LarsDenBakker, where did you get to on this? I have the same problem with this polyfill when loading modules from a cdn. Any help would be greatly appreciated.