Skip to content
Nilay Kabariya

Entry No.013·Fixes·Updated ·4 min read

Fix: ERR_MODULE_NOT_FOUND Cannot find module in ES modules

Node can't find a file that is clearly there. What ES modules changed about relative imports, why TypeScript path aliases break at runtime, and what to change.

What changed on Nov 8, 2026: Re-ran on Node 20, 22, 24 and 26 with TypeScript 7.0.2 and added the .ts-vs-.js import case for Node's own TypeScript support.

The error, verbatim

Jump to the fix ↓
node:internal/modules/esm/resolve:275
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\project\src\utils' imported from C:\project\src\app.js
    at finalizeResolution (node:internal/modules/esm/resolve:275:11)
    at moduleResolve (node:internal/modules/esm/resolve:865:10)
    at defaultResolve (node:internal/modules/esm/resolve:991:11) {
  code: 'ERR_MODULE_NOT_FOUND'
}
✓ Reproduced on Windows 11 Pro

The fix that worked

Write it in every relative import:

import { add } from './utils.js';
Not it? Every cause, tested ↓

Tested on

Node
24.14.0 and 20.19.4; 20.20.2, 22.23.4, 24.22.2, 26.13.0 (Linux, November 8)
Module type
"type": "module"
TypeScript
5.9.3; 7.0.2 (November 8), module nodenext
OS
Windows 11 Pro

✓ Last re-run on GitHub Actions · see the run · all repros

Error [ERR_MODULE_NOT_FOUND]: Cannot find module in an ES module almost always means an import is missing its file extension, because ES modules don’t guess extensions the way require() did. That part is old news. What I didn’t find written down anywhere is that TypeScript run directly by Node needs the opposite of the usual advice: on Node 22, 24 and 26, node main.ts failed with this error on import './greet.js' and only worked with import './greet.ts', which plain tsc then rejects. The fix for both is below.

The fix

Write the file extension in every relative import:

import { add } from './utils.js';   // not './utils'

In TypeScript you still write .js, even though the file on disk is utils.ts. The extension you write is the one that exists after compiling:

import { hi } from './greet.js';    // greet.ts on disk

Importing a folder is a different error with the same cause, ERR_UNSUPPORTED_DIR_IMPORT. Point at the file:

import { mul } from './lib/index.js';   // not './lib'

Why it happens

CommonJS require() guessed for you. Given ./utils it tried utils.js, then utils.json, then utils/index.js. ES modules don’t guess: the import string is resolved as a URL, so ./utils means a file literally named utils, and when there’s none, resolution stops.

That’s why the message quotes a path with no extension and points inside node:internal/modules/esm/resolve rather than at anything you wrote. The file exists; the name you asked for doesn’t.

Running .ts files with Node: write .ts, not .js

Current Node releases run TypeScript files directly by stripping the types (it worked on 22.23.4, 24.22.2 and 26.13.0 in my test), and for those files the rule above flips. On November 8, 2026 I ran the same three imports of greet.ts on Node 20, 22, 24 and 26 with TypeScript 7.0.2:

Terminal on GitHub Actions with Node 24.22.2 and TypeScript 7.0.2: extensionless and folder imports fail with ERR_MODULE_NOT_FOUND and ERR_UNSUPPORTED_DIR_IMPORT; experimental-specifier-resolution changes nothing; node main.ts fails for './greet' and './greet.js' and works for './greet.ts'; tsc rejects './greet.ts' with TS5097 until rewriteRelativeImportExtensions, which compiles it to './greet.js' and the output runs.
Node 24.22.2; Node 22.23.4 and 26.13.0 gave identical results. Full log.
Import in main.ts node main.ts (22, 24, 26) tsc, module: nodenext
'./greet' ERR_MODULE_NOT_FOUND error TS2835 (see below)
'./greet.js' ERR_MODULE_NOT_FOUND compiles
'./greet.ts' runs error TS5097

Node doesn’t map .js back to .ts: it looks for a real greet.js, finds none, and throws. So code written the tsc way crashes when you run it with Node directly, and code written the Node way doesn’t compile:

error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.

Write .ts in the imports and let tsc rewrite them when it compiles:

{ "compilerOptions": { "module": "nodenext", "rewriteRelativeImportExtensions": true } }

On Node 20.20.2, running a .ts file at all fails earlier, with ERR_UNKNOWN_FILE_EXTENSION: that’s its own post.

The TypeScript path-alias version

This one costs people the most time, because the code compiles cleanly and fails only when it runs.

{ "compilerOptions": { "paths": { "@/*": ["src/*"] } } }
import { hi } from '@/greet.js';

tsc accepts it. But paths only teaches the type checker where to look; it does not rewrite anything. The compiled file still says:

import { hi } from '@/greet.js';

and Node has never heard of @/:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\project\dist\greet' imported from C:\project\dist\main.js

Two ways out, both verified on this project:

1. Node’s own aliases, which exist at runtime. Add an imports map to package.json (the keys must start with #):

{
  "imports": { "#lib/*": "./dist/*" },
  "type": "module"
}
import { hi } from '#lib/greet.js';

2. Keep @/ and run through a resolver that understands it. tsx reads paths from tsconfig.json:

npx tsx src/main.ts

What didn’t work

If you can’t face adding extensions everywhere

TypeScript will tell you exactly where they’re missing, with the corrected path, if you set "module": "nodenext":

error TS2835: Relative import paths need explicit file extensions in ECMAScript
imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './greet.js'?

That turns a runtime crash into a compile-time list you can work through once.

Run it yourself

The November 8 matrix above is the err-module-not-found folder in nk-repro (run 42507222760). The original project:

The project I used is on GitHub, so you can trigger the error on your own machine in under a minute:

git clone https://github.com/nils44344/node-ts-error-repros
cd node-ts-error-repros/02-err-module-not-found
npm install && npm run repro

Test setup

A small ES module project ("type": "module") with a relative import, a folder import and a TypeScript build using paths, run on Node 24.14.0 and Node 20.19.4 with TypeScript 5.9.3. Every error and every fix above is the real terminal output from that project.

— N.K., end of entry No.013

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.023

    Fix: TypeScript enum is not supported in strip-only mode

    Node's ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX for enum, parameter properties, namespace, export = and import =. Two ways to run it unchanged, both tested.

    > enum Color { Red, Green }

    FIXED4 min
  2. No.014

    TS1294: syntax not allowed with 'erasableSyntaxOnly', fixed

    TS1294: TypeScript rejects your enum, namespace or constructor shorthand. Why new projects turn this on, what each piece becomes, and when to switch it off.

    > src/a.ts(1,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.

    FIXED4 min
  3. No.012

    Unknown file extension ".ts" (ERR_UNKNOWN_FILE_EXTENSION)

    Node refuses to run your TypeScript file. The version where this stops happening, what ts-node has to do with it, and the one-line way to run .ts today.

    > node:internal/modules/esm/get_format:189

    FIXED5 min

tip: paste the exact error text