Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

772
Views
jest No se pueden encontrar módulos dentro de la carpeta node_modules cuando se usa el compilador swc (Siguiente, js)

Tengo un proyecto con Next.js y quería hacer algunas pruebas unitarias en él. Seguí las instrucciones provistas aquí y logré hacer algunas pruebas. también es bueno mencionar que estoy usando el compilador de óxido y mecanografiado para el proyecto.

pero hay un problema con una de las pruebas al cargar un módulo desde la carpeta node_modules. aquí está la salida:

 $ 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)

cualquier otra cosa que no sean los componentes dentro del proyecto me da este error.

aquí está la configuración de broma para el proyecto:

 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)

¿alguien puede ayudar en cuanto a por qué sucede esto?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!