开玩笑无法找到模块FileName.css(映射为identity-obj-proxy) [英] Jest Could not locate module FileName.css (mapped as identity-obj-proxy)

查看:253
本文介绍了开玩笑无法找到模块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:\Users\admin\Documents\myApp
> 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

这篇关于开玩笑无法找到模块FileName.css(映射为identity-obj-proxy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆