# moduleResolution

> The `moduleResolution` TypeScript compiler option defines how the compiler finds the files of imported modules.

## Which moduleResolution should I use in TypeScript?

The compiler option that sets the strategy for resolving imports. The 'bundler' value suits projects with bundlers, and 'nodenext' follows the rules of Node.js ES modules. The legacy 'node10' value is deprecated.

- Topic: Modules
- Type: concept

## Example

Wrong:

```json
{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node"
  }
}
```

Right:

```json
{
  "compilerOptions": {
    "module": "nodenext",
    "moduleResolution": "nodenext"
  }
}
```

'nodenext' follows Node's real ESM and CommonJS rules, including `exports` maps, unlike the legacy 'node' mode.

## Common mistakes

- Imports work in the editor but fail at runtime in Node because extensions were left out.

## Key points

- Apps built by a bundler use 'bundler', Node packages and scripts use 'nodenext', not the old 'node'.
- With 'nodenext', relative imports in ES modules include the file extension, e.g. './utils.js'.
- `moduleResolution` and `module` are set together, as 'nodenext' requires `module: 'nodenext'`.

## Interview questions

### Why do I import './utils.js' when the file is utils.ts?

With 'nodenext' the import path must match the emitted file. TypeScript maps './utils.js' back to 'utils.ts' when checking.

### Does moduleResolution: 'bundler' support package exports?

Yes. It reads the `exports` field of `package.json` and allows imports without file extensions, like most bundlers.

### Does moduleResolution make paths aliases work at runtime?

No. `paths` only affects type checking; the bundler or runtime needs its own alias config.

## Related cards

- [tsconfig.json](https://wonderium.dev/ts/tsconfig-json.md)
- [Compiler Options](https://wonderium.dev/ts/compiler-options.md)
- [verbatimModuleSyntax](https://wonderium.dev/ts/verbatim-module-syntax.md)
- [import / export](https://wonderium.dev/js/import-export.md)
- [package.json](https://wonderium.dev/processes/package-json.md)

---

- Level: [TypeScript](https://wonderium.dev/ts.md)
- HTML version: https://wonderium.dev/ts/module-resolution
- Last updated: 2026-11-25
