Encountering an Error:
While attempting to import the "v4" UUID package from the Deno std lib, I faced an error that puzzled me. It seemed to arise when a dependency was resolved transitively in multiple steps. To address this issue in my project, I decided to re-export all dependencies in a file named deps.ts
at the root of my project:
[...]
// exporting UUID from standard library
export {
v4
} from "https://deno.land/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bac9cedefa8a948c89948a">[email protected]</a>/uuid/mod.ts";
[...]
Later on, in a script intended for the client-side, I tried importing the module using a relative path and encountered issues whilst trying to use it:
// encountering an error while compiling
import { v4 } from "../deps.ts";
[...]
const myNewUUID = v4.generate();
Solution Implemented:
I found a workaround by having the consuming module directly import the external module without any indirect references (via URL):
// successfully compiles and functions
import { v4 } from "https://deno.land/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4a7a0b094e4fae2e7fae4">[email protected]</a>/uuid/mod.ts";
[...]
const myNewUUID = v4.generate();
This peculiar issue did not surface when dealing with other std modules. Interestingly, even after reloading the modules in deps.ts
using deno cache --reload deps.ts
, they still failed to resolve with the aforementioned error. It remains uncertain whether this problem is specific to the v4 UUID package or if it could occur with other modules as well.
If anyone can shed light on the underlying reasons behind this complex error resulting from the import strategy described above, please share your insights. At present, resorting to the mentioned workaround seems like a reasonable approach.
Note for OP: The inclusion of libraries "dom" and "deno.ns" in your tsconfig.json file necessitates specifying the target JS level, such as "es2018", according to the documentation ("Don't forget to include the JavaScript library").