从'index.js'中找不到模块'react-dnd',但是Jest能够找到:“ ../../my_component.js”

时间:2020-01-17 12:12:57

标签: reactjs jestjs babel-jest

我在当前项目中使用“ react-sortable-tree” npm软件包(使用它创建一个组件),该软件包具有“ react-dnd”的外部依赖性。

虽然渲染时,组件看起来还不错,但是在使用玩笑测试同一组件时,它会抛出:-

从'index.js'中找不到模块'react-dnd'

However, Jest was able to find:
    '../../../src/MyComponent.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['', 'js', 'jsx', 'json'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at Object.<anonymous> (node_modules/frontend-collective-react-dnd-scrollzone/lib/index.js:24:17)

我现在的jest.config.js看起来像:-

module.exports = {
"setupFiles": [
    "<rootDir>/enzyme.config.js"
],
transformIgnorePatterns: ["/!node_modules"], //basically allowing jest to transform everything in node _modules
transform: { 
    '.*': 'babel-jest'
},
moduleFileExtensions: ['','js', 'jsx', 'json']
};

我已经解决了一天,但找不到错误。任何人都可以对此提供帮助或建议。 版本信息:-

  1. 通天塔:7
  2. 笑话:24.9
  3. babel-jest:24.9

0 个答案:

没有答案