venrilV
Denoβ€’14mo 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 is resolved to cwd + location, but I just want it to be
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
Was this page helpful?