无法在模块外部使用 import.meta。维特测试

Sim*_*rde 8 reactjs jestjs vite

我正在使用 vite 和 jest 进行测试。当我运行测试时出现此错误

这是我的 .babelrc 文件babelrc

这是我的 vite.config vite 配置

有人有解决方案吗?我已经搜索过但没有找到任何答案

更新: 我在 babel.config.js 上添加了这个

//babel.config.js

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      { useBuiltIns: 'entry', corejs: '2', targets: { node: 'current' } },
    ],
    '@babel/preset-typescript',
  ],
  plugins: [
    function () {
      return {
        visitor: {
          MetaProperty(path) {
            path.replaceWithSourceString('process')
          },
        },
      }
    },
  ],
}
Run Code Online (Sandbox Code Playgroud)

但现在我收到这个错误

错误