reactjs - 开玩笑 - 无法从“source-map-support.js”中找到模块“source-map”
问题描述
我遇到了错误的问题:
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)
如果我尝试用 Jest 运行测试。
我的 .babelrc 看起来像这样:
{
"presets": ["env", "react"],
"sourceMaps": "both",
"plugins": [
"add-module-exports",
"react-hot-loader/babel",
"source-map-support"
]
}
我的 package.json 看起来像这样:
{
"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"
]
}
}
测试本身似乎没问题,但我还是得到了错误。
我尝试了不同的解决方案:
- 有人说有必要将这些配置添加到 package.json 中:
"jest": {
"moduleDirectories": [
"node_modules",
"src"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx"
]
}
但我也没有运气。有人可以帮忙吗?
解决方案
在 VS Code 中使用 Jest 测试运行程序时遇到此问题。从https://github.com/facebook/jest/issues/6880#issuecomment-441499110中获取指针,我注意到我的jest.config.js
包含
moduleDirectories: ["<rootDir>/node_modules", "<rootDir>/ClientApp"]
将其更改为
moduleDirectories: ["node_modules", "ClientApp"]
解决了这个问题。
推荐阅读
- javascript - 电话号码的Angular 7输入掩码
- swift - StackView 内的 UILabel 的 UITapGestureRecognizer
- android - 如何检测android中的滚动视图是否可滚动
- python-3.x - 一个单一的 Tkinter 窗口,它在帧中移动,将每一帧带到前台。一帧需要分成两个子帧
- 3d - 对象模式和编辑模式之间的根本区别是什么?
- c++ - 将列表指针传递给函数的问题
- javascript - 使用 Express JS 阻止来自客户端的不需要的请求
- android - 高度大于宽度的屏幕的 Android Studio 布局资源
- java - 正则表达式得到 1) 而不仅仅是数字
- javascript - 一次向数组中的每个元素添加一个classList - 纯js