parcel icon indicating copy to clipboard operation
parcel copied to clipboard

non-static `import()` becomes a regular `require`

Open mischnic opened this issue 1 year ago • 1 comments

This no longer works:

	const url = 'https://cdn.skypack.dev/jszip@^3.10.0';
	const {default: JSZip} = await import(url);

because import is turned into a require

Screen Shot 5

I just found out that this is even documented: https://en.parceljs.org/javascript.html

Screen Shot 8

but it fails as is:

Screen Shot 7

Generated code:

Screen Shot 6

Originally posted by @fregante in https://github.com/parcel-bundler/parcel/issues/7064#issuecomment-1186107582

mischnic avatar Jul 17 '22 17:07 mischnic

I just found out that this is even documented: en.parceljs.org/javascript.html

(That are the docs for Parcel 1.x.)

mischnic avatar Jul 17 '22 17:07 mischnic

As an egregious workaround, the dynamic import can be wrapped inside an eval:

await eval(`import("https://cdn.jsdelivr.net/pyodide/v0.23.2/full/pyodide.js")`);

nanoskript avatar May 12 '23 13:05 nanoskript