tslib should follow standards for ESM/CJS detection
See original GitHub issuetslib’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:
- There is no
"type": "module"
field, which tells node code that .js files support ESM - The ESM tslib (currently
"tslib.es6.js"
) should have an .mjs file extension - The CJS tslib (currently `“tslib.js”) should have a .cjs file extension.
To be clear, just the type
field would help, but I think it would be preferable to complete all 3 at once.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
tslib - npm
tslib. This is a runtime library for TypeScript that contains all of the TypeScript helper functions. This library is primarily used by the ......
Read more >How to Create and Publish a React Component Library
This tutorial will take you through the process of creating and publishing your own custom React component library and hosting it on Github....
Read more >tslib direct dependency migration - Angular
If you have any libraries within your workspace, this migration will convert tslib peer dependencies to direct dependencies for the libraries.
Read more >tslib - githubmemory
tslib repo issues. ... If my TS target is ES2017 for an Electron app, does tslib even do anything? ... tslib should follow...
Read more >Two problems about tslib,about microsoft/tslib - GithubHelp
... Package tslib has been ignored because it contains invalid configuration HOT 2; tslib should follow standards for ESM/CJS detection HOT 8 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @wmertens - there are 2 fixes I’ve used:
moduleNameMapper
section, eg:This is hard-coded in
jest-preset-angular
b/c the ability to resolve tslib ES6 in jest is broken (thus this issue).tslib.es6.js
and rename it totslib.mjs
- jest (and node) always treat .mjs files as ESM. Then put it in a place, or update webpack config, so that it’s linked instead ofnode_modules/tslib
.@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.