I've found the solution to this problem... which isn't a problem at all. It is also answered here: Cannot find module jest-sequencer-@jest/test-sequencer!

So... never ever tick Caught Exceptions and Uncaught Exceptions in VS Code:

Without those two ticks, jest works out of the box.

Answer from LukasHT on Stack Overflow
🌐
GitHub
github.com › jest-community › vscode-jest › issues › 382
Test suite failed to run - Cannot find module · Issue #382 · jest-community/vscode-jest
September 20, 2018 - Environment node -v: v8.11.3 npm -v: 5.6.0 npm ls jest or npm ls react-scripts (if you haven’t ejected): $ npm ls jest /Users/hnjoshi/repos/my-app/content/private/react └── jest@23.3.0 your vscode-jest settings if customized: "jest.runAl...
Author   hnjoshi
Discussions

Upgrade to v28 complains "Cannot find module '@jest/expect'"
@testing-library/react version: 13.2.0 Testing Framework and version: jest 28.1.0 DOM Environment: "jest-environment-jsdom": "^28.1.0", "react": "^18.1.0", R... More on github.com
🌐 github.com
5
May 17, 2022
node.js - Jest gives `Cannot find module` when importing components with absolute paths - Stack Overflow
These says that each module you ... first in node_modules, then in src. Since the code is already looking in the src/, you should use: ... Please note that this path is absolute to the src directory, you do not have to navigate to locate it as relative path. Or you can configure your root directory in moduleDirectories inside your Jest configuration ... More on stackoverflow.com
🌐 stackoverflow.com
Jest: Cannot find module error?
You might need to mock it. https://jestjs.io/docs/mock-functions More on reddit.com
🌐 r/reactjs
6
2
November 7, 2022
Error: Cannot find module 'jest-util'
I've installed the package as devDependency and ran node --inspect --debug-brk ./node_modules/.bin/jest --runInBand -i --env jest-environment-node-debug, but it threw an error: FAIL test/specs/... More on github.com
🌐 github.com
2
May 10, 2017
🌐
GitHub
github.com › danger › danger-js › issues › 83
jest-environment-node missing · Issue #83 · danger/danger-js
January 6, 2017 - Trying to add to artsy/elderfield#42 > elderfield@0.0.1 danger /home/travis/build/artsy/elderfield > danger module.js:327 throw err; ^ Error: Cannot find module 'jest-environment-node' at Function.Module._resolveFilename (module.js:325:1...
Author   dblock
🌐
Jest
jestjs.io › configuring jest
Configuring Jest · Jest
October 14, 2025 - To make a dependency explicit instead of implicit, you can call expect.addSnapshotSerializer to add a module for an individual test file instead of adding its path to snapshotSerializers in Jest configuration. More about serializers API can be found here. ... The test environment that will be used for testing. The default environment in Jest is a Node.js environment.
🌐
GitHub
github.com › testing-library › jest-dom › issues › 457
Upgrade to v28 complains "Cannot find module '@jest/expect'" · Issue #457 · testing-library/jest-dom
May 17, 2022 - @testing-library/react version: 13.2.0 Testing Framework and version: jest 28.1.0 DOM Environment: "jest-environment-jsdom": "^28.1.0", "react": "^18.1.0", Relevant code or config: import { render } from '@testing-library/react'; import ...
Published   May 17, 2022
Author   tettoffensive
🌐
GitHub
github.com › NikhilVerma › jest-environment-node-debug-fixed › issues › 6
Error: Cannot find module 'jest-util' · Issue #6 · NikhilVerma/jest-environment-node-debug-fixed
May 10, 2017 - I've installed the package as devDependency and ran node --inspect --debug-brk ./node_modules/.bin/jest --runInBand -i --env jest-environment-node-debug, but it threw an error: FAIL test/specs/index.test.jsx ● Test suite failed to run Cannot find module 'jest-util' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (node_modules/jest-environment-node-debug/index.js:3:40) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) Is this due to https://github.com/NikhilVerma/jest-environment-node-debug-fixed/blob/master/index.js#L3 ?
Published   May 10, 2017
Author   hirokith
Find elsewhere
🌐
npm
npmjs.com › package › jest-environment-node
jest-environment-node - npm
March 10, 2026 - Latest version: 30.3.0, last published: a month ago. Start using jest-environment-node in your project by running `npm i jest-environment-node`. There are 1181 other projects in the npm registry using jest-environment-node.
      » npm install jest-environment-node
    
Published   Mar 10, 2026
Version   30.3.0
🌐
GitHub
github.com › jestjs › jest › issues › 14289
Jest setup for esm modules. Error "Cannot find module" · Issue #14289 · jestjs/jest
June 29, 2023 - Error "Cannot find module"#14289 · Copy link · Labels · 💬 Question · Volna13 · opened · on Jun 29, 2023 · Issue body actions · I am switching from cjs to esm. I've fixed all the issues except jest running issues. He just refuses to work. Here is datails. /jest.config.js · export default { preset: 'ts-jest', testEnvironment: 'node', transform: {}, setupFilesAfterEnv: ['./src/tests/jest.setup.ts'], }; /src/tests/jest.setup.ts ·
Author   Volna13
🌐
GitHub
github.com › mswjs › msw › issues › 1786
"Cannot find module 'msw/node'" in Jest JSDOM environment · Issue #1786 · mswjs/msw
October 23, 2023 - The test should pass, as it does if you switch to the Node environment by updating jest.config.js as follows: diff --git a/jest.config.js b/jest.config.js index f343a5c..4e07134 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,5 +13,5 @@ module.exports = { ReadableStream, TextEncoder, }, - testEnvironment: "jsdom", + testEnvironment: "node", };
Author   textbook
🌐
Stack Overflow
stackoverflow.com › questions › 76956124 › jest-test-environment-node-experimental-vm-modules-node-modules-jest-bin-jest
Jest: Test environment node --experimental-vm-modules node_modules/jest/bin/jest.js cannot be found
module.exports = { testEnvironment: 'node --experimental-vm-modules node_modules/jest/bin/jest.js', testMatch: [ '**/tests/**/*.test.mjs' ], transform: {}, transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ], moduleFileExtensions: [ 'js', 'mjs', 'json', 'node' ], globals: { 'ts-jest': { useESM: true } } };
🌐
GitHub
github.com › nrwl › nx › issues › 10825
Can't find libraries when running Jest tests · Issue #10825 · nrwl/nx
June 21, 2022 - Cannot find module '@org/shared:ui' from 'src/header/header.tsx' "next": "^12.1.5", "@nrwl/cypress": "14.3.1", "@nrwl/eslint-plugin-nx": "14.3.1", "@nrwl/jest": "14.3.1", "@nrwl/js": "14.3.1", "@nrwl/linter": "14.3.1", "@nrwl/next": "14.3.1", "@nrwl/node": "14.3.1", "@nrwl/react": "14.3.1", "@nrwl/storybook": "14.3.1", "@nrwl/tao": "14.3.1", "@nrwl/web": "14.3.1", "@nrwl/workspace": "14.3.1", "jest": "^28.1.1", "jest-environment-jsdom": "^28.1.1", Reactions are currently unavailable ·
Author   jberrydev
🌐
GitHub
github.com › wmonk › create-react-app-typescript › issues › 154
Error: Cannot find module '/home/user/test/node_modules/jest-cli' · Issue #154 · wmonk/create-react-app-typescript
August 31, 2017 - Environment npm ls react-scripts-ts (if you haven’t ejected): └── (empty) node -v: v8.4.0 npm -v: 5.3.0 yarn --version (if you use Yarn): 0.27.5 Operating system: Ubuntu 14.04 Steps to Reproduce create-react-app test --scripts-version=re...
Author   comerc
Top answer
1 of 3
14

If someone has a problem with a package not resolved by jest, e. g.

Copy    Cannot find module '@private-registry/private-package' from 'user_block.vue'

  13 |     >
  14 |       <template v-slot:activator="{ on }">
> 15 |         <v-avatar
     |                    ^
  16 |           :color="white ? '#f2f2f2' : color"
  17 |           :class="[
  18 |             'mp-user-avatar',

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at src/components/lib/components/user_block.vue:15:20
  at Object.<anonymous> (src/components/lib/components/index.ts:75:42)

Then you should check the package.json main field inside the installed package folder (with that example, it's ./node_modules/@private-registry/private-package/package.json. If there's no main field or the main field points to a wrong (nonexistent) file, then that's the problem. It was a problem in my case at least.


If that doesn't help, you can also try to walk with a console.log through node_modules/jest-resolve/build/index.js and node_modules/jest-resolve/build/defaultResolver.js like I did.

2 of 3
4

Following @Crysknight answer, I came up with a solution for my project:

Only adding main entry in package.json didn't worked. So I added a console.log to show me the error message in node_modules/jest-resolve/build/resolver.js. The message was Error: No known conditions for "." entry in "foo" package.

Opening the library package.json I see:

...
"exports": {
  ".": {
    "import": "./dist/foo.core.mjs",
    "types": "./dist/foo.d.ts"
  },
  "./*": "./*"
},
...

The problem was, the entry require was missing, so I added the following:

...
"exports": {
  ".": {
    "require": "./dist/foo.esm.mjs",
    "import": "./dist/foo.core.mjs",
    "types": "./dist/foo.d.ts"
  },
  "./*": "./*"
},
...

And now it's working :D hope this answer can help someone.

🌐
Medium
medium.com › @python-javascript-php-html-css › resolving-cannot-find-module-error-in-react-testing-with-react-markdown-f42c07ab5674
Resolving ‘Cannot Find Module’ Error in React Testing with React-Markdown
November 4, 2024 - The moduleNameMapper configuration maps specific paths to modules, which helps Jest resolve missing files or dependencies by directing it to alternative locations in node_modules. ... Setting testEnvironment to “jsdom” creates a simulated browser environment for Jest tests.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1283189 › jest-exception-cannot-find-module-with-spfx-soluti
Jest exception "cannot find module" with spfx solutions - Microsoft Q&A
npm install enzyme enzyme-adapter-react-16 react-test-renderer @types/enzyme --save-dev --save-exact npm install jest jest-junit ts-jest @types/jest --save-dev --save-exact
🌐
GitHub
github.com › jest-community › vscode-jest › issues › 671
Setup issues, can't find module · Issue #671 · jest-community/vscode-jest
February 28, 2021 - Environment node -v: v14.15.4 npm -v: 6.14.10 npm ls jest or npm ls react-scripts (if you haven’t ejected): `-- react-scripts@3.4.4 your vscode-jest settings if customized: launch.json config: { "type": "node", "name": "vscode-jest-tests...
Author   yunti
🌐
Reddit
reddit.com › r/nextjs › anyone ever have issues getting jest set up correctly in a next app?
r/nextjs on Reddit: Anyone ever have issues getting Jest set up correctly in a Next app?
July 7, 2022 -

Trying to have the simplest set up possible, having issues where Jest can't resolve paths to react components imported from my `components` directory, like the below.

import FooComponent from "components/bar/foo"

When I run jest, I will see an error like

Cannot find module 'components/bar/foo' from 'components/some/other/component'

Below is my jest config, ripped form the docs

const nextJest = require("next/jest");

const createJestConfig = nextJest({
  // Provide the path to your Next.js app to load next.config.js and .env files in your test environment
  dir: "./",
});

// Add any custom config to be passed to Jest
const customJestConfig = {
  moduleNameMapper: {
    // Handle module aliases (this will be automatically configured for you soon)
    "^@/components/(.*)$": "<rootDir>/components/$1",

    "^@/pages/(.*)$": "<rootDir>/pages/$1",
  },
  testEnvironment: "jest-environment-jsdom",
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);

Anyone see where my issue is?