DenoDDeno
Powered by
venrilV
Denoβ€’16mo ago
venril

Dynamic import with absolute path outside of project directory

Dynamic Importing seems to only work relative to the current projects directory, but I want to load things from outside the project directory. As you can see,
p
p
is resolved to cwd + location, but I just want it to be
location
location
. Is it this possible, or do I have to bring all possible modules under the project directory?
      const location = "C:\\Users\\me\\modules\\mod1\\mod1.ts";
      const importLocation = new URL(
        `File://${location}`,
        import.meta.url,
      ).href; // 'file:///C:/Users/me/modules/mod1/mod1.ts'

      const p = import.meta.resolve(importLocation); // 'file:///C:/Users/me/projects/tsrunner2/runner_server/src/Users/me/modules/mod1/mod1.ts'

      const module = await import(importLocation); // fails because resolves to same as `p` above
      const location = "C:\\Users\\me\\modules\\mod1\\mod1.ts";
      const importLocation = new URL(
        `File://${location}`,
        import.meta.url,
      ).href; // 'file:///C:/Users/me/modules/mod1/mod1.ts'

      const p = import.meta.resolve(importLocation); // 'file:///C:/Users/me/projects/tsrunner2/runner_server/src/Users/me/modules/mod1/mod1.ts'

      const module = await import(importLocation); // fails because resolves to same as `p` above
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

dynamic import fail
ElektraEElektra / help
2y ago
(In IntelliJ) Deno: Failed to load the import map at <absolute_path> (...)
nikovic97Nnikovic97 / help
3y ago
Import from variable path?
PhatsoPPhatso / help
4y ago