Jest 找不到模块 FileName.css(映射为 identity-obj-proxy) [英] Jest Could not locate module FileName.css (mapped as identity-obj-proxy)
本文介绍了Jest 找不到模块 FileName.css(映射为 identity-obj-proxy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试为我的 React 项目设置测试环境,但在导入 CSS 文件时遇到了意外令牌问题.我将 moduleNameMapper 添加到 package.json 以修复它,现在我正面临这个问题.有谁知道我能做些什么来解决这个问题?
I've been trying to set up a testing environment for my React project and I had a problem with Unexpected token when importing the CSS file. i added the moduleNameMapper to the package.json to fix it and now i'm facing this issue. Does anyone know what can i do to fix this?
> myProject@0.0.1 test C:UsersadminDocumentsmyApp
> jest
FAIL _tests_Home.test.js
● Test suite failed to run
Configuration error:
Could not locate module react-datepicker/dist/react-datepicker-cssmodules.css (mapped as identity-obj-proxy)
Please check:
"moduleNameMapper": {
"/^.+.(css|less)$/": "identity-obj-proxy"
},
"resolver": undefined
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.894s
Ran all test suites.
npm ERR! Test failed. See above for more details.
package.json 的笑话部分
jest portion of package.json
"jest": {
"transform": {
"^.+\.jsx?$": "babel-jest"
},
"moduleNameMapper": {
"\.(s?css|less)$": "identity-obj-proxy"
}
},
推荐答案
确保你的 devDependencies 中有 identity-obj-proxy
make sure you have identity-obj-proxy in your devDependencies
"devDependencies": {
"identity-obj-proxy": "^3.0.0",
...
}
如果没有,运行
npm install --save-dev identity-obj-proxy
这篇关于Jest 找不到模块 FileName.css(映射为 identity-obj-proxy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文