javascript - 用 babel 问题配置 jest - “找不到模块”错误
问题描述
所以我一直在尝试配置 jest 基本测试,但没有成功。我无法导入任何 React 模块或函数。
我的 jest.config.js:
module.exports ={
moduleNameMapper: {
'\\.(css|scss)$': '<rootDir>/__mocks__/styleMock.js',
'^meteor/(.*)': '<rootDir>/__mocks__/meteorMocks.js'
},
transform: {
'^.+\\.js?$': 'babel-jest'
},
transformIgnorePatterns: ['node_modules/(?!@foobar)/'],
modulePaths:['<rootDir>/ui']
};
babel.config.json:
{
"plugins": ["@babel/plugin-proposal-class-properties",
"@babel/transform-runtime",
"@babel/plugin-proposal-optional-chaining",
["@babel/plugin-proposal-decorators", { "legacy": true }]
],
"presets": [
"@babel/preset-react",
"@babel/preset-env"
]
}
错误:无法从“ui/components/elements/collections/TablePagination.js”中找到模块“/ui/components/SimpleLoading”
Require stack:
ui/components/elements/collections/TablePagination.js
ui/components/elements/ChatWidget.js
ui/components/ElementRenderer.js
8 |
9 | // import { composeCollectionFields } from '/ui/components/collectionEditor/utils';
> 10 | import Loading from '/ui/components/SimpleLoading';
我知道这个问题出现了很多次,但似乎没有一个能为我解决它。任何帮助表示赞赏。谢谢!