Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

773
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda