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

355
Views
jest cannot resolve node modules subpath pattern imports

i build project using node express and using https://nodejs.org/api/packages.html#packages_subpath_patterns to prevent "../../../xxx.js"

I added this to package.json and working perfectly

"imports": {
  "#src/*": "./src/*.js"
}

But the problem when i tried to running test from jest i got this error

Cannot find module '#src/config/database.js' from 'src/database/connection.js'

    Require stack:
      src/database/connection.js
      test/admin.test.js

      1 | import { MongoClient } from "mongodb";
    > 2 | import databaseConfig from "#src/config/database.js";
        | ^


      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:311:11)
      at Object.<anonymous> (src/database/connection.js:2:1)

I don't know how to solve this issue, tried to find solution from googling and documentation cannot find similar problem with this

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Add this in your Jest Configuration (e.g. jest.config.json)

"moduleNameMapper": {
    "#src/(.*)": "<rootDir>/src/$1"
}

See the moduleNameMapper attribute in Jest configuration docs.

over 4 years ago · Santiago Trujillo Report
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!