Ts-jest: Jest-config is missing as a dependency in package.json

Created on 1 Oct 2018  路  14Comments  路  Source: kulshekhar/ts-jest

Issue :

There exists imports of the form: import * as jestConfig from 'jest-config' in ts-jest. However, jest-config is not listed as a dependency in package.json. This sometimes causes problems in repositories using pnpm for package management.

Expected behavior :

Dependencies of ts-jest to be explicitly listed in the package.json

All 14 comments

jest-config is included with jest. If you don't have jest-config then there is an issue with your dependencies. jest is in the peer deps of ts-jest.

If you think this is still an issue, please reopen and comment.

@huafu jest-config is a separate package from jest, can you clarify what you mean by it being included in jest?

@christiango jest-config is in jest dependencies. ts-jest has jest as a peer dependency. So it means ts-jest needs the user to install jest (to be precise, a version >=22 and <24). By installing jest, it'll also install the correct version of jest-config since it's in jest dependencies. That is to avoid the user to have a jest-config version not compatible with its version of jest.

Lemme know if there is still something unclear.

screen shot 2018-10-01 at 21 51 16

I think the issue you're having is with pnpm which does not make a flat node_modules :/

@huafu Yeah, one of the reasons we use PNPM is to enforce that packages can only access the packages they define as dependencies in package.json.

Jest itself doesn't require jest-config as a dependency: https://github.com/facebook/jest/blob/master/packages/jest/package.json

It is however a dependency of jest-cli, which jest depends on.
https://github.com/facebook/jest/blob/master/packages/jest-cli/package.json

It feels strange that ts-jest is depending on package being installed just because it is a dependency of a dependency of jest. Fortunately we're able to work around this issue in our repo.

Thanks!

I just ran into this as well, I'm just using npm. [email protected] was working fine, then I upgraded to 23.10 and every test failed with Cannot find module 'jest-config'. I wasn't familiar with that module, it isn't listed as a peer dependency, or a dependency of jest so I manually installed it (npm install jest-config --save-dev) and ts-jest started working again.

@aaronbeall since you use npm, it looks like you have unsynced node_modules folder. Remove jest-config from your dep list, ensure you have the latest version of jest and ts-jest in your package.json. Then remove the whole node_modules directory and finally run npm i to get a fresh, in sync node_modules dir

@huafu Thanks for the response. I did try deleting node_modules and running npm install but I get the same result. It only works if I manually install jest-config. I tried jest --clearCache and got the same results.

@aaronbeall i need a minimal repo where to reproduce the issue then, can't help like that

@huafu Yeah, I understand, thanks for your help. Indeed a fresh install with just jest and ts-jest works fine without jest-config. Yet even though I do have [email protected] and [email protected] in my main project it is refusing to work without jest-config as well... I'll try to narrow it down.

Ok, so I got it to go away. I have no idea how. The only somewhat suspect thing was that it happened after I noticed I had "jest-cli": "23.6.0" which didn't seem necessary, so I uninstalled it. Immediately afterwards test started completing. However, re-installing jest-cli doesn't make the error come back, but after uninstalling/installing/updating/deleting node_modules on a bunch of times it did come back. Eventually I got it to go away again with similarly random seeming sequence of deleting node_modules and re-installing. So I don't know what to make of it... but at least I'm smooth sailing again! Thanks so much.

You should have in your devDependencies: jest, ts-jest, typescript, @types/jest and maybe @types/node for tests to work. Nothing else should be there related to jest, even in dependencies (no jest-cli, babel-jest, ...)

It feels strange that ts-jest is depending on package being installed just because it is a dependency of a dependency of jest.

It does feel strange. So why doesn't ts-jest add the thing it actually depends on as a dependency? Is it because if that version mismatches what jest is using, bad things can happen?

@mikew if we add jest-config as a dependency and you want to use another version of jest than the one corresponding to the version of our jest-config, it might fail because of jest trying to use some API of jest-config not existing, or changed. jest-config is a dependency of jest, so it's ts-jest to check compatibility with any version and not jest.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

remcohaszing picture remcohaszing  路  4Comments

bruk1977 picture bruk1977  路  3Comments

japhar81 picture japhar81  路  3Comments

jbreckmckye picture jbreckmckye  路  3Comments

artola picture artola  路  3Comments