0
0
DenoDebug / FixBeginner · 3 min read

How to Fix Module Not Found Error in Deno Quickly

In Deno, a module not found error usually happens because the import path is incorrect or missing the file extension. Fix it by using a full URL or a relative path with the proper file extension like .ts or .js in your import statements.
🔍

Why This Happens

Deno requires explicit and correct module paths including file extensions or full URLs. If you omit the file extension or use a wrong path, Deno cannot find the module and throws a module not found error.

typescript
import { serve } from "https://deno.land/std/http/server.ts";
import { myFunc } from "./utils";  // Missing file extension
Output
error: Import 'file:///path/to/project/utils' failed: NotFound: No such file or directory (os error 2)
🔧

The Fix

Always include the full file extension in local imports, like .ts or .js. For remote modules, use the full URL including the version if possible. This helps Deno locate the module correctly.

typescript
import { serve } from "https://deno.land/std@0.203.0/http/server.ts";
import { myFunc } from "./utils.ts";
Output
No errors. Modules loaded successfully.
🛡️

Prevention

To avoid this error in the future:

  • Always specify file extensions in local imports.
  • Use exact URLs with versions for remote modules.
  • Use Deno linting tools (deno lint) to catch import mistakes early.
  • Organize your files clearly and use relative paths carefully.
⚠️

Related Errors

Other common errors include:

  • 404 Not Found when a remote URL is wrong or the version does not exist.
  • Permission Denied if Deno lacks permission to read local files.
  • Type Errors if the imported module does not export what you expect.

Check URLs, permissions, and exports carefully to fix these.

Key Takeaways

Always include file extensions in local import paths in Deno.
Use full URLs with versions for remote module imports.
Run 'deno lint' to catch import path errors early.
Check permissions if local files cannot be accessed.
Verify remote URLs and versions to avoid 404 errors.