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

766
Views
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
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!