question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module '@shelf/jest-mongodb'

See original GitHub issue

I must be doing something stupid, but I can’t seem to resolve @shelf/jest-mongodb. Here’s a minimal repro:

$ npm i -D @shelf/jest-mongodb

$ echo "require('@shelf/jest-mongodb')" > test.js

$ node test.js

internal/modules/cjs/loader.js:626
    throw err;
    ^

Error: Cannot find module '@shelf/jest-mongodb'

At the same time,

$ cat node_modules/@shelf/jest-mongodb/package.json | grep name

    "name": "@shelf/jest-mongodb",

Any other package (incl. scoped) works. Originally ran into this with jest. I needs to use both ts-jest and @shelf/jest-mongodb, so I require both and then merge them with my own overwrites.

Env:

  • node -v: v12.3.1
  • npm -v: 6.9.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
Borduhhcommented, Oct 5, 2019

Had a similar issue and like @alex996 said, all Jest presets are just JS objects. Therefore you can merge them. He chose to use the merge NPM package, but you can also just use the object spread notation.

Here is my jest.config.js file:

const tsPreset = require('ts-jest/jest-preset');
const mongoPreset = require('@shelf/jest-mongodb/jest-preset');

const jestOverwrites = {
  testMatch: ['**/src/tests/**/?(*.)+(spec|test).ts?(x)'],
};

module.exports = { ...tsPreset, ...mongoPreset, ...jestOverwrites };
6reactions
KnupMancommented, Jun 3, 2019

Can you please explain why do you need to resolve it? If you wanna to use @shelf/jest-mongodb library properly, please look at the readme: https://github.com/shelfio/jest-mongodb#usage You just need to add the library as Jest preset: image

Read more comments on GitHub >

github_iconTop Results From Across the Web

@shelf/jest-mongodb - npm
Run your tests using Jest & MongoDB in Memory server. Latest version: 4.1.4, last published: a month ago. Start using @shelf/jest-mongodb in ...
Read more >
Error with jest config: "Preset @shelf/jest-mongodb not found."
Deleting the package-lock.json, and node_modules folder, then installing packages again; Removing everything but the preset from the jest.config ...
Read more >
shelf/jest-mongodb NPM - npm.io
Make sure mongodb is installed in the project as well, as it's required as a peer dependency. 1. Create jest.config.js. module.exports ...
Read more >
Error with jest presets: “Preset @shelf/jest-mongodb not found.”
I have tried every combination of characters i can think of in the 'preset' field to get it to find the node_module, and...
Read more >
Using with MongoDB - Jest
Jest MongoDB provides all required configuration to run your tests using MongoDB. First install @shelf/jest-mongodb. npm; Yarn. npm ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found