jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.2k stars 505 forks source link

`tsdx test` errors: `Cannot find module 'babel-jest'` #1110

Open stephencweiss opened 2 years ago

stephencweiss commented 2 years ago

Current Behavior

When I run yarn test my code it now breaks.

Expected behavior

I'd expect the test report to run successfully.

Suggested solution(s)

A clearer understanding of how babel-jest needs to be configured to avoid this problem -- it appears that tsdx can't find the module babel-jest... but it's listed as a dependency due tsdx when I run yarn why.

Additional context

The key point here is that my main branch works just fine, a feature branch breaks on this and it's unclear to me why. The only changes to dependencies were:

// package.json
+       "@rollup/plugin-url": "^6.1.0",
+      "@svgr/rollup": "^6.2.1",

No changes to jest.config

Related question: https://github.com/jaredpalmer/tsdx/issues/688

yarn test
yarn run v1.22.4
$ tsdx test --passWithNoTests --coverage
/Users/stephen.weiss/code/olo/expo-web-ui/node_modules/tsdx/dist/index.js:385
        throw err;
        ^

Error: Cannot find module 'babel-jest'
Require stack:
- /Users/stephen.weiss/code/olo/expo-web-ui/node_modules/tsdx/dist/createJestConfig.js
- /Users/stephen.weiss/code/olo/expo-web-ui/node_modules/tsdx/dist/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.resolve (internal/modules/cjs/helpers.js:80:19)
    at Object.createJestConfig (/Users/stephen.weiss/code/olo/expo-web-ui/node_modules/tsdx/dist/createJestConfig.js:7:35)
    at /Users/stephen.weiss/code/olo/expo-web-ui/node_modules/tsdx/dist/index.js:388:73
    at Sade.parse (/Users/stephen.weiss/code/olo/expo-web-ui/node_modules/sade/lib/index.js:189:56)
    at Object.<anonymous> (/Users/stephen.weiss/code/olo/expo-web-ui/node_modules/tsdx/dist/index.js:462:6)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/stephen.weiss/code/olo/expo-web-ui/node_modules/tsdx/dist/createJestConfig.js',
    '/Users/stephen.weiss/code/olo/expo-web-ui/node_modules/tsdx/dist/index.js'
  ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn why babel-jest -R
yarn why v1.22.4
[1/4] 🤔  Why do we have the module "babel-jest"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "babel-jest@25.5.1"
info Reasons this module exists
   - "tsdx#jest#@jest#core#jest-config" depends on it
   - Hoisted from "tsdx#jest#@jest#core#jest-config#babel-jest"
✨  Done in 0.74s.

Your environment

%  npx envinfo --system OS --browsers --binaries --npmPackages tsdx,typescript --npmGlobalPackages tsdx,typescript
npx: installed 1 in 1.211s

  System:
    OS: macOS 11.6.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 1.11 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.22.3 - ~/.volta/tools/image/node/12.22.3/bin/node
    Yarn: 1.22.4 - ~/.volta/tools/image/yarn/1.22.4/bin/yarn
    npm: 6.14.13 - ~/.volta/tools/image/node/12.22.3/bin/npm
  Browsers:
    Brave Browser: 98.1.35.100
    Chrome: 97.0.4692.99
    Firefox: 91.0.2
    Safari: 14.1.2
    Safari Technology Preview: 15.4
  npmPackages:
    tsdx: ^0.14.1 => 0.14.1
    typescript: ^4.2.3 => 4.2.3
aladdin-add commented 2 years ago

sometimes yarn did not dedupe babel-jest, just try:

stephencweiss commented 2 years ago

Thanks @aladdin-add! I'll give it a shot!