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

767
Visualizações
jest Cannot find modules inside node_modules folder when using swc compiler (Next,js)

I have a project with Next.js and wanted to do some unit tests on it. I followed the instruction provided here and managed to make some tests. it's also good to mention that I'm using the rust compiler and typescript for the project.

but there is an issue with one of the tests when loading a module from the node_modules folder. here is the output:

$ jest
info  - Loaded env from /Projects/projectname/.env
 PASS  test/pages/index.test.tsx
 PASS  components/shared/ui/Button/Button.test.tsx
 FAIL  components/shared/ui/Card/Card.test.tsx
  ● Test suite failed to run

    Cannot find module 'swiper/react' from 'components/attraction/Gallery/Gallery.tsx'

    Require stack:
      components/attraction/Gallery/Gallery.tsx
      components/attraction/Gallery/index.ts
      components/attraction/index.ts
      components/index.ts
      components/shared/ui/Card/Card.tsx
      components/shared/ui/Card/Card.test.tsx

      1 | import { IImageResponse } from '@/constants'
      2 | import React, { useState } from 'react'
    > 3 | import { Swiper, SwiperSlide } from 'swiper/react'
        |                                                   ^
      4 | import SwiperCore, { Pagination } from 'swiper'
      5 | import styles from './Gallery.module.scss'
      6 |

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
      at Object.<anonymous> (components/attraction/Gallery/Gallery.tsx:3:51)

anything other than the components inside the project gives me this error.

here is the jest config for the project:

const nextJest = require('next/jest')

const createJestConfig = nextJest({
  // Provide the path to your Next.js app to load next.config.js and .env files in your test environment
  dir: './',
})

// Add any custom config to be passed to Jest
const customJestConfig = {
  setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
  moduleNameMapper: {
    // Handle module aliases (this will be automatically configured for you soon)
    '^@/(.*)$': '<rootDir>/$1',
  },
  testEnvironment: 'jest-environment-jsdom',
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)

can anyone help as to why this is happening?

about 4 years ago · Juan Pablo Isaza
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