Deno uses modern ES modules (ESM) as its standard module system. Unlike Node.js, Deno does not support CommonJS require() by default (except for Node.js compatibility mode). All modules use standard import and export syntax.
Deno’s module system is built on web standards, using the same import syntax as browsers.
// Named importsimport { serve } from "https://deno.land/std@0.220.0/http/server.ts";// Default importsimport express from "npm:express@4";// Namespace importsimport * as path from "node:path";// Type-only importsimport type { Handler } from "./types.ts";// Dynamic importsconst module = await import("./dynamic.ts");
// Package with versionimport express from "npm:express@4.18.2";// Latest versionimport chalk from "npm:chalk";// With subpathimport { parse } from "npm:yaml@2.3.1/parse";
# Force reload from sourcedeno run --reload script.ts# Reload specific modulesdeno run --reload=https://deno.land/std script.ts# Clear cachedeno cache --reload script.ts
// Current module URLconsole.log(import.meta.url);// => file:///home/user/project/main.ts// Resolve relative to current moduleconst configPath = new URL("./config.json", import.meta.url);// Check if module is mainif (import.meta.main) { console.log("Running as main module");}
// Import TypeScript directlyimport { User } from "./types.ts";import { Database } from "./db.ts";// No need for .js extensions// No tsconfig.json required// No build step needed
// Goodimport { utils } from "./utils.ts";// Bad - will not workimport { utils } from "./utils";
Pin Remote Module Versions
// Good - pinned versionimport { serve } from "https://deno.land/std@0.220.0/http/server.ts";// Bad - unpinned, can breakimport { serve } from "https://deno.land/std/http/server.ts";
// Error: Missing file extensionimport { x } from "./module"; // ❌import { x } from "./module.ts"; // ✅// Error: Relative import without ./import { x } from "utils.ts"; // ❌import { x } from "./utils.ts"; // ✅// Error: Missing permissionsimport { x } from "https://example.com/mod.ts"; // ❌ without --allow-net
Learn More
Explore TypeScript support to understand how Deno compiles TypeScript without configuration.