Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 1.41 KB

README.md

File metadata and controls

38 lines (30 loc) · 1.41 KB

Minimal Typescript to build native ESM example

The goal of this is to combine the modern things of node.js in single project: ESM module system and Typescript.

Note that at this moment, the CommonJS module system is still the default target for Typescript https://www.typescriptlang.org/tsconfig#module '...You very likely want "CommonJS" for node projects'. Indeed it is reasonable to proceed with CommonJS for libraries for better compatibility, see default tsconfig.json node.js v18. However for applications, ESM should be fine and this is why that project has been created.

The key settings of 'tsconfig.json' is:

{
  "complilerOptions": {
    "module": "NodeNext"
  }
}

unit tests

The unit tests require some additional attention. The test folder is excluded in 'tsconfig.json'. They also need node --loader=ts-node/esm to run properly. Without this seeting it throws TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts". See package.json for detailed configuration. There are bothe node-tap and mocha tests.

resources