[SalesForce] Cannot find module ‘@jest/globals’ from ‘abc.test.js’

Has anyone encountered this kind of an error? We had a bunch of jest js files that were working a few months but now are failing. Can any JEST experts help?

Best Answer

This was an unfortunate mismatch between dependencies of dependencies when using the base LWC Jest testing packages. More specifically, if you happen to get a babel-preset-jest version < 25.5.4 but are running jest version >= 25.5.4. The exact version of these dependencies probably depends on when you installed or upgraded your dependencies and what your package-lock.json or yarn.lock look like.

The fix is to upgrade all Jest related dependencies to be >= 25.5.4, or pin them all below. If you're using @salesforce/sfdx-lwc-jest to run your tests, this was fixed already in the prerelease branch.

This was fixed in the sfdx-lwc-jest project here: https://github.com/salesforce/sfdx-lwc-jest/pull/152

Related Topic