I've got the problem that I get the error:
Cannot find module 'source-map' from 'source-map-support.js'
Ran all test suites matching /Foo-test/i.
T:\public_html\testProj>jest Foo-test
FAIL //XXXX.de/XXXX/Users/XXX/public_html/testProj/src/__tests__/Foo-test.js
? Test suite failed to runtml/testProj/src/__tests__/Foo-test.js
Cannot find module 'source-map' from 'source-map-support.js'
at Resolver.resolveModule (T:/public_html/testProj/node_modules/jest-resolve/build/index.js:221:17)
If I try to run a test with Jest.
My .babelrc looks like this:
{
"presets": ["env", "react"],
"sourceMaps": "both",
"plugins": [
"add-module-exports",
"react-hot-loader/babel",
"source-map-support"
]
}
My package.json looks like this:
{
"name": "testproject",
"version": "1.8.0",
"main": "index.js",
"license": "MIT",
"private": true,
"devDependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"copy-webpack-plugin": "^4.5.2",
"css-hot-loader": "^1.3.9",
"eslint": "4.9.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-import": "2.7.0",
"eslint-plugin-jsx-a11y": "6.0.2",
"eslint-plugin-react": "7.4.0",
"file-loader": "^1.1.11",
"foundation-sites": "^6.4.4-rc1",
"node-sass": "^4.8.3",
"prettier": "^1.14.2",
"react-hot-loader": "4.1.3",
"sass-loader": "^6.0.7",
"source-map": "^0.7.3",
"webpack": "^4.0.1",
"webpack-cli": "^2.0.9",
"webpack-dev-server": "^3.0.0"
},
"dependencies": {
"@material-ui/core": "^1.5.0",
"axios": "^0.18.0",
"babel-jest": "^23.6.0",
"chai": "^4.2.0",
"core-js": "^2.5.3",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"jest": "^23.6.0",
"prop-types": "^15.6.0",
"react": "^16.3.0",
"react-accessible-accordion": "^2.4.4",
"react-dom": "^16.3.0",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
"react-string-replace": "^0.4.1",
"redux": "^3.7.2",
"redux-thunk": "^2.3.0",
"sinon": "^7.0.0"
},
"scripts": {
"dev": "webpack-dev-server --hot",
"build": "webpack --colors --profile --progress --env.mode production",
"lint": "eslint ./src/ --ext .js,.jsx",
"test": "jest"
},
"jest": {
"moduleDirectories": [
"node_modules",
"src"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx"
]
}
}
The test itself seems to be ok, but I get the error nevertheless.
I tried different solutions:
-Some people say it would be necessary to add these configs to the package.json:
"jest": {
"moduleDirectories": [
"node_modules",
"src"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx"
]
}
But I had no luck with that either. Can someone help here?
Hit this issue when using a Jest test runner in VS Code.
Taking a pointer from https://github.com/facebook/jest/issues/6880#issuecomment-441499110, I noticed that my jest.config.js
contained
moduleDirectories: ["<rootDir>/node_modules", "<rootDir>/ClientApp"]
Changing it to
moduleDirectories: ["node_modules", "ClientApp"]
fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With