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.
Upgrade to v28 complains "Cannot find module '@jest/expect'"
node.js - Jest gives `Cannot find module` when importing components with absolute paths - Stack Overflow
Jest: Cannot find module error?
Error: Cannot find module 'jest-util'
I think you're looking for: roots or modulePaths and moduleDirectories
You can add both relative and absolute paths.
I would make sure to include <rootDir> in the roots array, <rootDir> in the modulePaths array, and node_modules in the moduleDirectories array, unless you've got a good reason to exclude them.
"jest": {
"roots": [
"<rootDir>",
"/home/some/path/"
],
"modulePaths": [
"<rootDir>",
"/home/some/other/path"
],
"moduleDirectories": [
"node_modules"
],
}
In package.json you have the below lines of Jest configuration:
"moduleDirectories": [
"node_modules",
"src"
]
These says that each module you import will be searched for first in node_modules, then in src.
Since the code is already looking in the src/, you should use:
import AppContainer from 'views/app';
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 (in your case, within package.json) so that all your components could be easily found.
The app is working perfectly fine but Jest is giving me an error when I import the component.
The error I'm getting is:
Cannot find module 'swiper/react' from 'src/components/ProductImages/ProductImages.tsx'
The module is installed. Why this this happening?
» npm install jest-environment-node
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.
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.
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?