Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.4K
Visualizações
Jest and Typescript: Cannot use import statement outside a module

Im trying to run unit tests in a monorepo where I have configured Jest and Typescript as below:

Jest:

module.exports = {
  displayName: 'xplat-web-features',
  preset: '../../../../jest.preset.js',
  globals: {
    'ts-jest': {
      tsconfig: '<rootDir>/tsconfig.spec.json',
    },
  },
  transform: {
    '^.+\\.[tj]sx?$': 'ts-jest',
  },
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
  coverageDirectory: '../../../../coverage/libs/xplat/web/features',
};

TSConfig:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../../../dist/out-tsc",
    "module": "commonjs",
    "types": ["jest", "node"]
  },
  "include": [
    "**/*.spec.ts",
    "**/*.spec.tsx",
    "**/*.spec.js",
    "**/*.spec.jsx",
    "**/*.d.ts"
  ]
}

And when I run Jest with the nx command, I get SyntaxError: Cannot use import statement outside a module

I have tried the following with no luck

  • Set babel-js as the transpiler in Jest config
  • Set "module" to es6 in compilerOptions of TS config
  • Run Jest with NODE_OPTIONS=--experimental-vm-modules

Basically hitting a wall at this point and don't know where to go from here.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Add this to your jest config file:

 "transform": {
     "^.+\\.ts?$": "ts-jest"
 }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda