esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

Parsing of `external` arg fails for scoped pkg names on `&extraQuery`

Open esroyo opened this issue 10 months ago • 4 comments

Specifying an external scoped package works fine with regular query parameters:

curl "https://esm.sh/@vue/[email protected]?external=@vue/shared"
/* esm.sh - @vue/[email protected] */
import "/@vue/[email protected]/X-ZUB2dWUvc2hhcmVk/es2022/runtime-core.mjs";
export * from "/@vue/[email protected]/X-ZUB2dWUvc2hhcmVk/es2022/runtime-dom.mjs";

However It fails when using the & query prefix to allow for importmap trailing slash:

curl "https://esm.sh/@vue/[email protected]&external=@vue/shared/"
module not found

Apparently It happens only when the external pkg is scoped (contains @?).

If not scoped, then seems to work fine:

curl "https://esm.sh/@vue/[email protected]&external=csstype/"
/* esm.sh - @vue/[email protected] */
import "/@vue/[email protected]/es2022/runtime-core.mjs";
import "/@vue/[email protected]/es2022/shared.mjs";
export * from "/@vue/[email protected]/X-ZWNzc3R5cGU/es2022/runtime-dom.mjs";

EDIT: probably the alias param has the same problem with @.

esroyo avatar Feb 05 '25 23:02 esroyo

@ije when possible, would be great if you could take a quick look and confirm that the expectations of this test case are correct: https://github.com/esroyo/esm.sh/commit/85ae4f024f505035dde459d683e3d51363b5c2b4

Thanks so much!

esroyo avatar Feb 12 '25 21:02 esroyo

I will look into it thanks 🙏

ije avatar Feb 13 '25 04:02 ije

This seems like a related issue:

        importMap.imports['@react-three/cannon'] =
            'https://esm.sh/@react-three/[email protected]?external=react,three,@react-three/fiber';

        importMap.imports['@react-three/cannon/'] =
            'https://esm.sh/@react-three/[email protected]&external=react,three,@react-three/fiber/';

The cannon import map doesn't work with the trailing slash and the @react-three/fiber external dependency. However, it does work if you remove the @react-three/fiber. That means I can't specify react-three/fiber as an external dependency though.

I get this error:

Image

Not sure what the workaround would be.

mliudev avatar Mar 14 '25 22:03 mliudev

This import map snippet works:

"@mui/material": "https://esm.sh/@mui/[email protected]?external=@emotion/react,@emotion/styled,react,react-dom"

This one does not:

"@mui/material/": "https://esm.sh/@mui/[email protected]&external=@emotion/react,@emotion/styled,react,react-dom/"

milochristiansen avatar Jun 25 '25 11:06 milochristiansen