ES Modules written in TypeScript running on Node.js
MIT License
Based on the Announcing a new experimental modules post from the Node team, this repository is an example of a TypeScript app running with the new experimental modules
feature shipped with Node.js 12. As explained in the linked post, it's now possible to use import
and export
syntax in .js
files, so ES Modules transpiled from TypeScript can be used out of the box π
.
βββ lerna.json
βββ package-lock.json
βββ package.json
βββ packages
βΒ Β βββ app //--> TypeScript app transpiled as an ES Module, using es-module dependency
βΒ Β βΒ Β βββ package-lock.json
βΒ Β βΒ Β βββ package.json
βΒ Β βΒ Β βββ tsconfig.json
βΒ Β βββ es-module //--> ES Module written in TypeScript
βΒ Β βββ package-lock.json
βΒ Β βββ package.json
βΒ Β βββ tsconfig.json
βββ tsconfig.settings.json
type: module
: New package.json field to treat all .js
files in project as ES Modules, see app and es-module files.--experimental-modules
: Flag to enable new experimental modules feature.--es-module-specifier-resolution=node
: By default, file extensions are mandatory in import. This flag enable CommonJS-style automatic extension resolution behavior. This flag is required because TypeScript does not add imported file extension in transpiled code.module: "esnext"
: Set the module code generation to esnext
, see inherited tsconfig.settings.json
nvm use
if you use nvm
npm install
npm run start
You should see the following JSON response:
{
"messages": ["Hello from ES Module dependency", "Hello from local ES Module"]
}
MIT Β© kevinpollet