Module not found: Error: Can't resolve 'meteor/mongo'

I started TDD development of my Meteor/Vue app using Cypress and documented how to get that running here: [Tutorial + Demo App] Testing Meteor Vue apps with Cypress

Now, I’m moving onto testing Mongo collections and am running into the following error

"Error: Webpack Compilation Error
./api/lists.js
Module not found: Error: Can't resolve 'meteor/mongo'"

This is the entirety of my list.js file:

import { Mongo } from "meteor/mongo";

export const Lists = new Mongo.Collection("lists");

I’ve tried “meteor npm install webpack-meteor-externals --save-dev” from: https://github.com/ardatan/meteor-webpack
and amended my “cypress/plugins/index.js” file (where webpack options can be put in without having to create a webpack.config.js file) with

const meteorExternals = require('webpack-meteor-externals');
    //...
    externals: [
        meteorExternals()
    ]
    //...

but then I get an error that Package in ““module.exports = Package[‘mongo’];”” cannot be found. I tried tracking down where Package was defined but no luck.

I’d appreciate any help in solving this problem.

You have the mongo package installed?

See .meteor/packages

I have the mongo package installed as I’m able to create mongo collections and insert data.

1 Like

Did you ever get this resolved? I believe the issue is probably caused by "meteor/mongo"; not being an npm module but a meteor package.

I’m running into a similar issue with creating a custom command:

import { Meteor } from 'meteor/meteor';

Cypress.Commands.add('login', () => {
	Meteor.loginWithPassword('username', 'password', (e) => {
		if (e) {
			console.error(e);
			throw e;
		}
	});
});

This causes the error:
Module not found: Error: Can't resolve 'meteor/meteor' in '.../tests/cypress/support' resolve 'meteor/meteor' in '.../tests/cypress/support'

Trying to figure out how to fix it…

For now, I am using this workaround for this particular scenario but it isn’t ideal and will not work for others:

Cypress.Commands.add('login', () => {
	cy.window().then((win) => {
		// @ts-ignore
		win.Meteor.loginWithPassword('username', 'password', (e) => {
			if (e) {
				console.error(e);
				throw e;
			}
		});
	});
});

It’s been such a long time, I don’t remember. Am no longer in the Meteor ecosystem. Moved on to Vue/Nuxt/Quasar. They have much better support.