Typescript 删除导入文件上的babelrc-意外令牌后,Jest测试无法使用ts Jest运行

Typescript 删除导入文件上的babelrc-意外令牌后,Jest测试无法使用ts Jest运行,typescript,jestjs,ts-jest,Typescript,Jestjs,Ts Jest,类似问题: 我正在将js测试文件转换为ts文件,并使用ts jest。我知道,如果我开玩笑,我就不需要巴贝尔了。但是当我删除.babelrc文件时,当我运行测试时,会出现以下错误: Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

类似问题:

我正在将js测试文件转换为ts文件,并使用ts jest。我知道,如果我开玩笑,我就不需要巴贝尔了。但是当我删除.babelrc文件时,当我运行测试时,会出现以下错误:


    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    import InstAdapter from '../../../src/adapters/inst/base';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
tsconfig:

{
  "compilerOptions": {
    "target": "es6"
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./ts-dist",
    "strict": true
    "downlevelIteration": true,
    "typeRoots": [
      "./node_modules/@types",
      "./types"
    ]
    "allowSyntheticDefaultImports": true 
    "esModuleInterop": true 
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true 
  },
  "include": ["./src/**/*", "./config/**/*"],
  "exclude": ["./src/app/assets/*"]
}
jest.config.ts:

module.exports = {
  preset: 'ts-jest',
  transform: {
    '\\.(ts|tsx)$': 'ts-jest',
  },
  globals: {
    'ts-jest': {
      tsConfig: '<rootDir>/tsconfig.json',
    },
  },
};

module.exports={
预设:“ts笑话”,
转换:{
“\\(ts | tsx)$”:“ts笑话”,
},
全球:{
“开玩笑”{
tsConfig:“/tsConfig.json”,
},
},
};
没有巴贝尔,有没有办法解决这个问题