Cannot find module "" from ""
rootDir
is referenced correctly. If not add this on your existing jest configuration.module.exports = {
...
roots: ["<rootDir>"]
}
module.exports = {
...
moduleDirectories: ["node_modules","<module-directory>"],
modulePaths: ["<path-of-module>"],
}
module.exports = {
...
moduleNameMapper: {
"<import-path>": "<rootDir>/<real-physical-path>",
},
}
git mv <source> <destination>
and commit changes.SyntaxError: Cannot use import statement outside a module
One of the node modules hasn't the correct syntax for Jests execution step. It needs to
be transformed first.
There is a good chance that the error message shows which module is affected:
SyntaxError: Cannot use import statement outside a module
> 22 | import Component from "../../node_modules/some-module/lib";
| ^
In this case some-module is the problem and needs to be transformed.
By adding the following line to the configuration file it will tell Jest which modules
shouldnt be ignored during the transformation step:
module.exports = {
...
transformIgnorePatterns: ["node_modules/(?!(some-module|another-module))"]
};
some-module and another-module will be transformed.