• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

327
Views
TypeScript tsconfig settings for Node.js 12?

What is the optimal TypeScript tsconfig settings for outputting code that's going to be run on Node.js 12?

about 3 years ago · Santiago Trujillo
3 answers
Answer question

0

As of Node.js 12.0.0, 100% of ES2019 is supported. If you know that you are targeting that version or newer, the optimal config would look like this:

  • "module": "commonjs"

    Node.js is on it's way to add ES-Modules, but for now we'll have to stick with CommonJS.

  • "target": "es2019"

    This tells TypeScript that it's okay to output JavaScript syntax with features from ES2019. In practice, this means that it will e.g. output object rest/spread properties & async/await syntax instead of embedding a polyfill.

  • "lib": ["es2019", "es2020.bigint", "es2020.string", "es2020.symbol.wellknown"]

    This tells TypeScript that it's okay to use functions and properties introduced in ES2019 or earlier. In practice, this means that you can use e.g. String.prototype.trimStart and Array.prototype.flat.

    In addition to ES2019, Node.js 12 also supports BigInt & matchAll from ES2020, therefor we include the additional definitions from ES2020.

The full config would thus be:

{
  "compilerOptions": {
    "lib": ["es2019", "es2020.bigint", "es2020.string", "es2020.symbol.wellknown"],
    "module": "commonjs",
    "target": "es2019"
  }
}

If you are targeting Node.js 12.9.0 or newer, you can simply specify "lib": ["es2020"] as that version supports all new functions and properties introduced in ES2020. It doesn't support the new JavaScript syntax though, so you still have to stay on "target": "es2019".

The full config would thus be:

{
  "compilerOptions": {
    "lib": ["es2020"],
    "module": "commonjs",
    "target": "es2019"
  }
}

If you are running Node.js 16 you can see my similar answer for Node.js 16 here

If you are running Node.js 14 you can see my similar answer for Node.js 14 here

If you are running Node.js 10 you can see my similar answer for Node.js 10 here

If you are running Node.js 8 you can see my similar answer for Node.js 8 here

about 3 years ago · Santiago Trujillo Report

0

TL:DR

TypeScript maintains a mapping of target, module and lib corresponding to the node version. You can find it here https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping

about 3 years ago · Santiago Trujillo Report

0

It is much easier using tsconfig bases.

Run npm install --save-dev @tsconfig/node12 and then in tsconfig.json

{
  "extends": "@tsconfig/node12/tsconfig.json",
  // ...your configrations
}

There is a few tsconfig bases for different environments and the community keeps adding more.

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error