Automatically upgrade from CommonJS to ESM with TS2ESM
HTML-код
- Опубликовано: 15 июл 2024
- Easily migrate your codebase from CommonJS to ECMAScript Modules Syntax with the TS2ESM tool.
My FREE programming apps:
- apps.apple.com/app/id659282498
- play.google.com/store/apps/de...
My FREE TypeScript Course:
- typescript.tv/
Timeline:
00:00 - Introduction to Modules
00:53 - Set up Node.js to use ESM
01:07 - Module & Module Resolution in TypeScript
01:43 - Fixing relative import paths
02:18 - The TS2ESM Migration Tool
02:50 - Fixing export declarations
03:26 - Use ESM in test files
04:22 - Test your ESM typings
04:45 - New JavaScript File Extensions
TS2ESM: github.com/bennycode/ts2esm
#typescript #nodejs #ecmascript Наука
Can you look into Jest compatibility problems with node js version 20+?
I suggest moving from Jest to Vitest (APIs are mostly compatible): github.com/bennycode/ts-node-starter/commit/662dddf92d418d0e1119a04d8f5fe807a7a566f0
tsnode does not work with node version 20-21. I started using the tsc compiler directly to transpile to Javascript and then run the generated file with node ./index.js
Have you tried tsimp instead of ts-node? ruclips.net/video/jn370WEIvjs/видео.html
This shouldn't be THE WAY, microsoft approves. This is a very ugly solution for a beautiful language. What is the point of writing js imports in a TS file. At least now we have Bun, I was about to give up Typescript because of this ESM incompatibility. These days TS popularity is dropping because of this complex mixture of module types. Tsc maintainers (Microsoft) cannot solve simple things like 'tsc --clean --watch' for years. Thanks for the video anyway.
Maybe we won't TS one day because JS will allow typings and then we have TS code that can be easily migrated as we don't have to touch the JS imports in it.