question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tslib should follow standards for ESM/CJS detection

See original GitHub issue

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:

  1. There is no "type": "module" field, which tells node code that .js files support ESM
  2. The ESM tslib (currently "tslib.es6.js") should have an .mjs file extension
  3. 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
johncrimcommented, Apr 10, 2022

Hi @wmertens - there are 2 fixes I’ve used:

  1. Explicitly link tslib.es6.js in your jest.config.js moduleNameMapper section, eg:
 ...
  moduleNameMapper: {
    tslib: 'tslib/tslib.es6.js',
  }
  ...

This is hard-coded in jest-preset-angular b/c the ability to resolve tslib ES6 in jest is broken (thus this issue).

  1. Create a copy of tslib.es6.js and rename it to tslib.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 of node_modules/tslib.
0reactions
wmertenscommented, Apr 12, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found