Skip to content

[Bug]: can't use ESM with external node modules that export commonjs and moduel files #3800

@rbnayax

Description

@rbnayax

Version

29.0.0

Steps to reproduce

  1. clone my repo - https://github.com/rbnayax/ts-jest-example
  2. run yarn
  3. run yarn test

Expected behavior

test should pass

Actual behavior

 FAIL  lib/fn/fn.spec.ts
  ● Test suite failed to run

    lib/fn/fn.ts:1:21 - error TS7016: Could not find a declaration file for module 'colorette'. '/home/regev/WebstormProjects/ts-jest-example/node_modules/colorette/index.cjs' implicitly has an 'any' type.
      Try `npm i --save-dev @types/colorette` if it exists or add a new declaration (.d.ts) file containing `declare module 'colorette';`

    1 import {green} from "colorette";
                          ~~~~~~~~~~~

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.761 s
Ran all test suites.
(node:415750) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

Debug log

link

Additional context

when removing the reference to 3rd party node module, everything works as expected

Environment

System:
    OS: Linux 5.14 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz
  Binaries:
    Node: 16.11.1 - ~/.nvm/versions/node/v16.11.1/bin/node
    Yarn: 3.2.1 - ~/.nvm/versions/node/v16.11.1/bin/yarn
    npm: 8.0.0 - ~/.nvm/versions/node/v16.11.1/bin/npm
  npmPackages:
    jest: ^29.0.2 => 29.0.2

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions