bombillazo
bombillazo6mo ago

Is there any way to force a Deno dependency to use a specific version of std?

We're having an issue were a dependency we are importing from npm with the npm: identifier is trying to use a node lib that only exisits up to std v0.177.0, specifically the tty lib. Our main std version is in 0.244.0 specified in our import_map.json file. Is there any way to specify this 3rd party dep to use the std version it requires to work?
1 Reply
Deno AI Helper
Deno AI Helper6mo ago
Yes, you can specify a specific version of the standard library (std) for a dependency by using an import map. Import maps allow you to remap import specifiers to different URLs, which can include specifying a particular version of a module. In your case, you want to ensure that the dependency which requires std version 0.177.0 uses that specific version, even though your main project uses std version 0.244.0. You can achieve this by creating an import map that maps the necessary std modules to the 0.177.0 version for that dependency. Here's an example of what your import map might look like:
{
"imports": {
"https://deno.land/std/tty/": "https://deno.land/std@0.177.0/tty/",
// ... other mappings ...
}
}
{
"imports": {
"https://deno.land/std/tty/": "https://deno.land/std@0.177.0/tty/",
// ... other mappings ...
}
}
In this import map, any imports from https://deno.land/std/tty/ will be redirected to use the 0.177.0 version of the tty module. To use the import map, you would run Deno with the --import-map flag, pointing to the location of your import map file:
deno run --import-map=import_map.json your_script.ts
deno run --import-map=import_map.json your_script.ts
Keep in mind that if the dependency you're using is not directly importing std modules but instead relying on another package that imports std modules, you might need to map those specific imports as well. The documentation also notes that if you don’t depend on these removed paths directly, but your transitive dependencies depend on these paths incorrectly with a non-versioned module URL, you might be unable to fix the issue by updating your own source code. In that case, using an import map as described above is the recommended approach. 🦕

Did you find this page helpful?