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.

🚀 Feature Proposal

Jest is working on supporting ESM https://github.com/facebook/jest/issues/9430 . We should consider lift up the hardcoded target: commonjs at some points.

Related discussion about detecting whether a file is esm or commonjs can be found here https://github.com/facebook/jest/issues/9860

Related issue: #1174

Motivation

Let ts-jest users as well as jest users take part in the ESM support development and testing.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:23
  • Comments:26 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
marcjcommented, Apr 30, 2021

@gadicc you simply import the TS files as usual, omitting the file extension.

6reactions
tstelzercommented, May 15, 2021

you simply import the TS files as usual, omitting the file extension.

This doesn’t make sense to me.

In an ESM project, imports will end with .js. Even when I omit the file extension in my test files, the code under test will import other modules, using .js files extensions. In other words:

// file: a.spec.ts
import * as a from './a'; // works

// file: a.ts
import * as b from './b.js'; // "Cannot find module './b.js' from './a.ts'

For what it’s worth, @gadicc workaround seems to work for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does it take to support Node.js ESM?
I have worked on all The Guild's libraries and graphql-js to support ESM. Here is how you can do it too.
Read more >
Getting Started with (and Surviving) Node.js ESM
The Node.js ecosystem is shifting towards ESM. We examine what lies in store for application and library authors, learn some of challenges ...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
Node.js fully supports ECMAScript modules as they are currently specified and ... Caveat: The ESM load hook and namespaced exports from CommonJS modules...
Read more >
"ESM" | Can I use... Support tables for HTML5, CSS3, etc
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >
supports-esm
Detect at runtime if Node.js supports ECMAScript modules. ... Start using supports-esm in your project by running `npm i supports-esm`.
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