deno relative path issue

Viewed 1011

I wanted to some prefixes for my imports like you can see in the code below:

"paths": {
          "~/*": ["../../libs/*"],
          "@/*": ["./*"]
        }

however I always get an relative import path "@/config.ts" not prefixed with / or ./ or ../ts(10001) when I try to import anything import User from "@/config.ts"

1 Answers

You can alias import specifiers by using an import map. From the Deno manual:

You can use import maps with the --import-map=<FILE> CLI flag.

Example:

import_map.json

{
   "imports": {
      "fmt/": "https://deno.land/std@0.125.0/fmt/"
   }
}

color.ts

import { red } from "fmt/colors.ts";

console.log(red("hello world"));

Then:

$ deno run --import-map=import_map.json color.ts
Related