Careeroza
target, module and moduleResolution
What Each Option Controls
| Option | Controls | Typical values |
|---|---|---|
target | which JavaScript syntax is emitted (older targets down-level ?., classes, async) | ES2022 for Node 18+, ES2017 for old browsers |
lib | which built-in APIs are known (Array.prototype.at, DOM) | ["ES2023", "DOM", "DOM.Iterable"] |
module | the module format emitted (require or import) | commonjs, esnext, nodenext, preserve |
moduleResolution | how import "x" is found on disk | bundler, nodenext, node10 |
Recommended Configs
Node.js
A modern Node.js service:
tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "nodenext",
"moduleResolution": "nodenext",
"strict": true,
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"skipLibCheck": true
},
"include": ["src"]
}Next.js
A Next.js / Vite app (the bundler emits the JavaScript, TypeScript only checks):
tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "bundler",
"jsx": "preserve",
"noEmit": true,
"isolatedModules": true,
"strict": true,
"paths": { "@/*": ["./src/*"] }
}
}lib Matters
Example
Object.groupBy was added in ES2024. With lib set to ES2023 (as here), TypeScript says it does not exist (TS2550, with a hint to change lib), even if your Node version has it. The second error follows from the first: the callback parameter could not be typed.
const orders = [{ city: "Pune", total: 500 }, { city: "Delhi", total: 900 }];
const byCity = Object.groupBy(orders, (o) => o.city);Compiler output (tsc)
Line 2: error TS2550: Property 'groupBy' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2024' or later. Line 2: error TS7006: Parameter 'o' implicitly has an 'any' type.