Latest Threat Research:Malicious dYdX Packages Published to npm and PyPI After Maintainer Compromise.Details
Socket
Book a DemoInstallSign in
Socket

jest-resolve-no-esm

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-resolve-no-esm

A jest-resolve fork that optionally disables the self-described "bad version" of Jest's attempt at replicating Node's type resolution algorithm

latest
Source
npmnpm
Version
31.9999.1
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

jest-resolve-no-esm

A jest-resolve fork that optionally disables the self-described "bad version" of Jest's attempt at replicating Node's type resolution algorithm.

Motivation

Jest's ESM support is too incomplete. Specifically:

  • There is no jest.requireActual function (e.g. a jest.importActual) for ES modules. This makes using jest.unstable_mockModule too annoying since, among other difficulties, I can't seem to import a module with the goal of modifying only a single of its exports while leaving the rest as they are. With something like jest.spyOn and babel-plugin-explicit-exports-references, this becomes is trivial. Unfortunately...

  • There is no jest.spyOn support in ESM mode because, as far as current Jest spying functionality is concerned, ES modules are immutable.

So, the solution is to just transpile everything back to CJS so we can regain our mocking and spying abilities. This has been my solution for a long time and it's been working perfectly fine up until (relatively) recently, where Jest updated its resolution algorithm in an attempt to progress its ESM support.

An unfortunate side-effect of this is that, even when transformIgnorePatterns: [] and transform: { ... } are configured in a Jest config file for full CJS transpilation, jest-resolve will still attempt to load the now-transpiled-CJS-module as if it were ESM just because its file names end in .js and the nearest package.json file contains "type": "module".

This fork allows me to disable ESM loading when process.env.JEST_RESOLVE_NO_ESM is truthy, which avoids false positive "errors" like Must use import to load ES Module: ....

[!NOTE]

For now, .mjs and .mts files will always be loaded as ESM even when using this module. This may be revisited later or, ideally, one day this entire package and other annoying workarounds will be obsoleted because Jest will support modern Node's ability to require ES modules natively.

Installation and Usage

  • Install:
npm install --save-dev jest-resolve@npm:jest-resolve-no-esm@30 jest

[!NOTE]

You may need to use the package.json overrides feature for a complete installation. See this package for an example.

  • Activate:
JEST_RESOLVE_NO_ESM=true npx jest

Alternatively, you could set process.env.JEST_RESOLVE_NO_ESM = 'true' in a Jest config file or setup file.

For example, unified-utils uses this package to test its ESM-only packages.

FAQs

Package last updated on 01 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts