[Bug]: can't use ESM with external node modules that export commonjs and moduel files
See original GitHub issueVersion
29.0.0
Steps to reproduce
- clone my repo - https://github.com/rbnayax/ts-jest-example
- run
yarn
- 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
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
Issue Analytics
- State:
- Created a year ago
- Comments:14
Top Results From Across the Web
TypeScript module "node16" does not work with CommonJS ...
Axios is declaring a default export in a CJS file. Typescript knows that ESM NodeJS will actually expose the module.exports as the "default ......
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
CJS scripts use require() and module.exports ; ESM scripts use import and export . ESM and CJS are completely different animals.
Read more >How to Create a Hybrid NPM Module for ESM and CommonJS.
Author your code in ES6, ES-Next or Typescript using import and export. From this base, you can import either ES modules or CommonJS...
Read more >Error [ERR_MODULE_NOT_FOUND]: Cannot find module
What am I doing wrong? You're mixing node's CJS module system (require/module. exports) with ES6 modules (import/export). Don't do that unless ...
Read more >CommonJS vs. ES Modules: Modules and Imports in NodeJS
In NodeJS each .js file is handled as a separate CommonJS module. ... The same way, we can import and use modules from...
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
removing the
preset
works for me when usingts-jest@29
, thanks @okitan 👍so maybe need to update the docs here: https://kulshekhar.github.io/ts-jest/docs/guides/esm-support#use-esm-presets as the example config is working fine on v28 but not in v29
@rbnayax
Have you tried removing
preset
from your config? I think setting bothpreset
andtransform
at once will cause two transformations.