Mark G
Mark G2w ago

Remap transient npm dependencies

Is there a way to remap npm dependencies to a http url? Let's say I import package 'jsr:@foo/a', which imports 'npm:@bar/b', can I remap that via my import map to https://.../bar/b.js? I basically want to remap some npm's to a cdn like jspm/esm etc, to avoid having a node_modules, for which there are reasons that I'm not going into, as I don't want to go off on tangental discussions.
1 Reply
Leokuma
Leokuma7d ago
That's not possible if the package is on JSR, because HTTP imports are not allowed in JSR. Example
import { Client } from "jsr:@luca/acme"; // `acme` uses `npm:jose`

console.log(Client);
import { Client } from "jsr:@luca/acme"; // `acme` uses `npm:jose`

console.log(Client);
{
"imports": {
"npm:jose@^6.0.8": "https://cdn.jsdelivr.net/npm/jose@^6.0.8/+esm"
}
}
{
"imports": {
"npm:jose@^6.0.8": "https://cdn.jsdelivr.net/npm/jose@^6.0.8/+esm"
}
}
$ deno run ...

error: Importing https://cdn.jsdelivr.net/npm/jose@^6.0.8/+esm blocked. JSR packages cannot import non-JSR remote modules for security reasons.
$ deno run ...

error: Importing https://cdn.jsdelivr.net/npm/jose@^6.0.8/+esm blocked. JSR packages cannot import non-JSR remote modules for security reasons.

Did you find this page helpful?