"moduleResolution"

The algorithm the compiler uses to find the files named in imports.

On this page

Example

#
JSON
{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "Bundler"
  }
}

Definition and usage

#

The moduleResolution option specifies how the compiler turns an import string, for example "react" or "./utils", into a specific file with code and types.

Bundler mimics the behavior of tools such as Vite and webpack: it lets you omit file extensions and understands the exports field in packages. NodeNext follows the exact rules of Node.js, where the extension in an import is mandatory in ES modules.

The older value Node (also called node10) doesn’t support the exports field and is no longer recommended in new projects.

Syntax

#
Syntax
"moduleResolution": "Bundler"

More examples

#
An import with an extension in NodeNext
TypeScript
// moduleResolution: "NodeNext", ES file
import { add } from './math.js'
// In NodeNext you give the .js extension, even when the source file is math.ts.

Good practices

#
  • In bundled applications, use Bundler, and in Node.js code, NodeNext.
  • If importing a package suddenly “has no types”, check whether moduleResolution understands that package’s exports field.

Related entries

#

Spotted a mistake or missing an example? Write to us.