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

211
Visualizações
Typescript Cannot find module in tests folder

I'm trying to add Jest to test my CLI written in Typescript but whenever I run jest it gives me the following error:

Cannot find module '../src/utils' or its corresponding type declarations.

This is my folder structure:

- tests
  - utils
    - index.ts
- src
  - utils
    - index.ts
  - Profiler.ts
  - index.ts
- webpack.config.js
- jest.config.ts
- tsconfig.json
- package.jsonf

This is my tsconfig.json

{
  "compilerOptions": {
    "target": "ES2016",
    "module": "commonjs",
    "rootDir": "src",
    "allowJs": false,
    "checkJs": false,
    "declaration": true,
    "declarationMap": true,
    "outDir": "./dist",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitAny": true,
    "alwaysStrict": true,
    "skipLibCheck": true
  }
}

This is my jest.config.ts

import type { Config } from "jest";
import { defaults } from "jest-config";

const config: Config = {
  preset: "ts-jest",
  testEnvironment: "node",
};

export default config;

May be important but VScode also throws this error enter image description here

And if I click on the path to go to the file, it says file not found and displays this path enter image description here

I'm pretty sure it has something to do with my tsconfig.json. I've tried adding both to src & test to rootDirs and a bunch of other things that I found online, like adding the paths to include but nothing has solved this.

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

0

if you are running the test from tests/utils/index.ts it would be ../../src/utils. As only going back one directory (../) would put you inside tests and then you look for a tests/src which does not exist

almost 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