Skip to content

/errors/deno/module-not-found

Deno: error: Module not found "file:///.../utils". Maybe add a '.ts' extension

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Deno
exit code
1
versions
Deno 2.x
os
any

error: Module not found "file:///.../utils" means Deno resolved an import to a local file that does not exist. Deno follows browser rules: an import is an exact URL or path, with the file extension, and nothing is guessed. Change import { add } from "./utils" to import { add } from "./utils.ts", and check the file name and its case.

Reproduce it

bash
cat > utils.ts <<'EOF'
export function add(a: number, b: number): number {
  return a + b;
}
EOF
cat > main.ts <<'EOF'
import { add } from "./utils";
console.log(add(1, 2));
EOF
npx --yes deno@2 run main.ts

Output · exit 1

error: Module not found "file:///tmp/work/utils". Maybe add a '.ts' extension or run with --sloppy-imports
    at file:///tmp/work/main.ts:1:21

utils.ts exists, but the import says ./utils, so Deno looks for a file literally named utils. Recent Deno 2 releases append a hint (Maybe add a '.ts' extension or run with --sloppy-imports) when a file with a known extension sits next to the missing path. The URL in the message is the absolute file:// path Deno computed, so compare it with the files you actually have. The at line shows which file and line contains the import.

Fix

Write the import with the extension (or create the missing file):

bash
cat > utils.ts <<'EOF'
export function add(a: number, b: number): number {
  return a + b;
}
EOF
cat > main.ts <<'EOF'
import { add } from "./utils.ts";
console.log(add(1, 2));
EOF
npx --yes deno@2 run main.ts

Output

3

Code migrated from Node.js

Node.js with a bundler or CommonJS often accepts ./utils and resolves ./utils.ts, ./utils.js or ./utils/index.ts. Deno does not. Options, from best to worst:

OptionWhen to use it
Add extensions to every relative importAlways the durable fix; TypeScript accepts .ts extensions in Deno projects
Map a name in deno.json "imports" (for example "@/": "./src/")Long relative paths or shared folders
--sloppy-imports (older releases: --unstable-sloppy-imports)A temporary bridge while migrating: Deno then guesses extensions and index files like Node.js tooling

A bare name such as import chalk from "chalk" produces a different error, Import "chalk" not a dependency, because it is a package, not a file.

Sources