Reactjs 找不到模块';反应dnd';从';index.js';,然而,杰斯特却能找到:“/”/我的“u component.js”;
我在当前项目中使用“react sortable tree”npm包(用它创建一个组件),它具有“react dnd”的外部依赖性 渲染时,组件看起来很好,但在使用jest测试同一组件时,它抛出:- 无法从“index.js”中找到模块“react dnd”Reactjs 找不到模块';反应dnd';从';index.js';,然而,杰斯特却能找到:“/”/我的“u component.js”;,reactjs,jestjs,babel-jest,Reactjs,Jestjs,Babel Jest,我在当前项目中使用“react sortable tree”npm包(用它创建一个组件),它具有“react dnd”的外部依赖性 渲染时,组件看起来很好,但在使用jest测试同一组件时,它抛出:- 无法从“index.js”中找到模块“react dnd” However, Jest was able to find: '../../../src/MyComponent.js' You might want to include a file extension in your im
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能够找到:
“../../../src/MyComponent.js”
您可能希望在导入中包含一个文件扩展名,或者更新“moduleFileExtensions”,当前为['''js','jsx','json']。
看见https://jestjs.io/docs/en/configuration#modulefileextensions-数组字符串
在Resolver.resolveModule(node_modules/jest resolve/build/index.js:259:17)
反对。(node_modules/frontend/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']
};
module.exports={
“设置文件”:[
“/enzyme.config.js”
],
transformIgnorePatterns:[“/!node_modules”],//基本上允许jest转换node_模块中的所有内容
转换:{
“.*”:“巴贝尔开玩笑”
},
moduleFileExtensions:['','js','jsx','json']
};
我在这附近工作了一天,但是没有发现这个bug。任何人都可以在这方面提供帮助或建议。提前谢谢。
版本信息:-
您正在将
testPathIgnorePatterns
设置为node\u modules
–react dnd
模式位于node\u modules
中,因此被Jest忽略,我很确定这会导致错误结果在从config中删除testPathIgnorePatterns
键后是相同的。上传了更新后的Jest.config.js。