使用 babel 问题配置 jest - “找不到模块”错误

时间:2021-05-18 12:48:40

标签: 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';

我知道这个问题出现了很多次,但似乎没有一个能帮我解决。感谢您的帮助。谢谢!

0 个答案:

没有答案
相关问题