Import maps

This is an unstable feature. Learn more about unstable features.

Deno supports import maps.

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

Current limitations:

  • single import map
  • no fallback URLs
  • Deno does not support std: namespace
  • supports only file:, http: and https: schemes

Example:

import_map.json

  1. {
  2. "imports": {
  3. "fmt/": "https://deno.land/std@$STD_VERSION/fmt/"
  4. }
  5. }

color.ts

  1. import { red } from "fmt/colors.ts";
  2. console.log(red("hello world"));

Then:

  1. $ deno run --importmap=import_map.json --unstable color.ts

To use starting directory for absolute imports:

  1. // import_map.json
  2. {
  3. "imports": {
  4. "/": "./"
  5. }
  6. }
  1. // main.ts
  2. import { MyUtil } from "/util.ts";

You may map a different directory: (eg. src)

  1. // import_map.json
  2. {
  3. "imports": {
  4. "/": "./src"
  5. }
  6. }