Improve ESM compatibility - #49
Conversation
This change follows the solution described in [1] to make the package play nice with both CommonJS and ESM clients. This includes: * Changing imports to use the .js extension explicitly * Modifying the dist/package.json file to refer to different directories depending on the context * Providing two package.json files that override the package type depending on the context Fixes: GH-37 [1] https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html
| "build:ts": "tsc -p tsconfig.json && tsc -p tsconfig.json -m esnext --outDir dist/esm/ -d false -declarationMap false", | ||
| "build:copy": "copyfiles README.md LICENSE src/package.json dist --flat && copyfiles src/rxjs-operators/package.json dist --up 1", | ||
| "build:ts": "tsc -p tsconfig-cjs.json && tsc -p tsconfig-esm.json", | ||
| "build:copy": "copyfiles README.md LICENSE src/package.json dist --flat && copyfiles src/rxjs-operators/package.json dist/cjs --up 1 && cp package-cjs.json dist/cjs/package.json && cp package-esm.json dist/esm/package.json", |
There was a problem hiding this comment.
I have not seen this approach in other packages. Have you seen other packages do it like that?
Did you see this?
https://www.the-guild.dev/blog/support-nodejs-esm
There was a problem hiding this comment.
Hey, I'm new to JS/TS packaging and I can't say I really know what other packages do. I followed https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html
|
Looking forward to seeing this merged as I use Thanks! |
|
We have https://github.com/lune-climate/ts-results-es ( |
|
I was looking into double exporting CJS/ESM a couple of weeks ago and I found that https://github.com/egoist/tsup makes the whole tooling much simpler and less error-prone. It reduced my build script down to: No need to copy files or defining multiple tsconfigs. |
|
@vultix Will this ever be merged or is this library dead (and we should use ts-results-es as a replacement)? |
This change follows the solution described in [1] to make the package
play nice with both CommonJS and ESM clients.
This includes:
depending on the context
depending on the context
Fixes: GH-37
[1] https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html