Open LinusU opened 3 years ago
@manuelbieh another approach would be to release a breaking change that drops CommonJS altogether. That would be my recommendation!
Many packages are moving to this since all current versions of Node.js supports ESM now 🚀
You can read about Sindres approach (which I, and many other maintainers are also using) here: https://github.com/sindresorhus/meta/discussions/15
It is as simple as:
yarn add --dev esbuild
yarn tsc
yarn esbuild dist/tsc/*.js --outdir=dist/tsc --minify --allow-overwrite
tsconfig.json:
{
"compilerOptions": {
"target": "es2017",
"lib": [
"es2018",
"dom"
],
"outDir": "dist/tsc",
"rootDir": "src/",
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": false,
"declaration": true,
"declarationDir": "dist/types",
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"strictNullChecks": true
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts"
],
"exclude": [
"node_modules",
"**/*.test.ts"
]
}
Some update?
When trying to import this library with the native support for ESM that's available in Node.js 12, 14, and 16 I'm running into the following problem:
According to the readme it seems like this should work:
I think that the problem is that the package.json is missing the
exports
key which describes how the module should be loaded by the native Node.js ESM.This is documented here: https://nodejs.org/api/packages.html#packages_package_entry_points
Basically, I think that something like this should be added:
I will try this and submit a PR if it works 🚀