-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tslib should follow standards for ESM/CJS detection #173
Comments
Node has documented their logic for determining whether a module is CJS or ESM. This appears to be what other other projects, eg jest, are using to determine what type of syntax to expect when loading js files. The node logic doesn't seem to address cases where both CJS and ESM files are published in a package, which seems like a major oversight. However, it should be possible to satisfy both while making no effective changes to tslib's package.json for clients depending on the current fields. |
@ahnpnl - I thought you might want to chime in on this issue, since you've done some work to special-case handling of tslib. |
What I experienced was: If using Possibly related to #161 (comment) |
So are there any workarounds right now? I'm an indirect consumer of tslib, does anybody have a working npm package I can enforce using instead? |
I tried changing tslib.js so it exports a plain object with the functions in there including __decorate, and Jest still doesn't work, same error 😓 |
as a workaround I made https://github.com/StratoKit/tslib |
Hi @wmertens - there are 2 fixes I've used:
...
moduleNameMapper: {
tslib: 'tslib/tslib.es6.js',
}
... This is hard-coded in
|
@johncrim when I try option 1. it complains that node_modules isn't transpiled, and I'd prefer to keep it that way, unless there's a way to tell jest to only transpile tslib? Option 2 is a variation of the package changes I made, so basically the same maintenance burden. |
In case it matters to anyone, I've also posted most of what's written below to evanw/esbuild#2296, as that issue is also quite related in my view. My main project uses just It's probably a bit hacky, but this relies on two details:
On second thought, it may be possible to add a resolution-phase plugin to do the redirect - the issue is about which For further enhancements, we've also developed this one: As is, the wrapping package approach unfortunately does not work well with
|
tslib's package.json has a few issues RE detecting whether it's CJS or ESM. Due to lack of standards support, it has to be special-cased in a number of places, eg jest-preset-angular. Workaround like this are needed in any projects using jest, typescript, and tslib.
The following changes to the package.json would fix things - happy to provide a PR if it will be considered:
"type": "module"
field, which tells node code that .js files support ESM"tslib.es6.js"
) should have an .mjs file extensionTo be clear, just the
type
field would help, but I think it would be preferable to complete all 3 at once.The text was updated successfully, but these errors were encountered: