Getting this error when trying to start the server:
Autostarting MongoDB instance...
Called MongoMemoryServer.start() method:
Called MongoMemoryServer.ensureInstance() method:
Starting MongoDB instance with following options: {
"port":40609,
"dbName":"testApp",
"uri":"mongodb://127.0.0.1:40609/testApp",
"storageEngine":"ephemeralForTest",
"dbPath":"/tmp/mongo-mem-22YBfrGxMHBL73",
"tmpDir":{
"name":"/tmp/mongo-mem-22YBfrGxMHBL73"
}
}
MongoBinary options: {
"downloadDir":"/builds/goniyo/api/testApp/node_modules/.cache/mongodb-memory-server/mongodb-binaries",
"platform":"linux",
"arch":"x64",
"version":"3.2.20"
}
Downloading:
RangeError: Maximum call stack size exceeded
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:1:1)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (/builds/goniyo/api/testApp/node_modules/graceful-fs/graceful-fs.js:201:29)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
I'm also experiencing this issue.
jest-mongodb-config.json:
module.exports = {
mongodbMemoryServerOptions: {
instance: {
dbName: 'jest',
},
binary: {
version: '3.6.10',
skipMD5: true,
},
autoStart: false,
debug: true,
},
};
package.json:
"dependencies": {
"auto-bind": "^1.2.1",
"crypto-js": "^3.1.9-1",
"dotenv": "^6.0.0",
"jasmine": "^3.1.0",
"joi": "^13.4.0",
"lodash": "^4.17.15",
"mongoose": "^5.5.3"
},
"devDependencies": {
"@shelf/jest-mongodb": "^1.1.0",
"@types/crypto-js": "^3.1.43",
"@types/dotenv": "^4.0.3",
"@types/jest": "^24.0.18",
"@types/joi": "^13.3.0",
"@types/lodash": "^4.14.109",
"@types/mongoose": "^5.5.17",
"coveralls": "^3.0.0",
"husky": "^0.14.3",
"jest": "^24.9.0",
"moment": "^2.24.0",
"mongodb-memory-server": "^5.2.1",
"nodemon": "^1.17.5",
"npm-run-all": "^4.1.3",
"prettier": "^1.13.5",
"pretty-quick": "^1.6.0",
"source-map-support": "^0.5.6",
"ts-jest": "^24.0.2",
"ts-node": "^6.1.0",
"tslint": "^5.10.0",
"typescript": "^2.9.2"
}
jest.config.json:
module.exports = {
roots: ['<rootDir>/test'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
setupFilesAfterEnv: ['./test/setup.ts'],
// testEnvironment: 'node',
preset: '@shelf/jest-mongodb',
};
Error message:
Called MongoMemoryServer.start() method:
Starting MongoDB instance with following options: {"port":65160,"dbName":"jest","uri":"mongodb://127.0.0.1:65160/jest","storageEngine":"ephemeralForTest","dbPath":"/tmp/mongo-mem-12946I3xta6eLIogK","tmpDir":{"name":"/tmp/mongo-mem-12946I3xta6eLIogK"}}
MongoBinary options: {"downloadDir":"/Users/kyleclawson/blockbrothers/mongo-models-repo/node_modules/.cache/mongodb-memory-server/mongodb-binaries","platform":"darwin","arch":"x64","version":"3.6.10","skipMD5":true}
Downloading:
● Test suite failed to run
RangeError: Maximum call stack size exceeded
at WriteStream (node_modules/graceful-fs/graceful-fs.js:199:24)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
at WriteStream (node_modules/graceful-fs/graceful-fs.js:201:29)
I am facing the same issue. Did anyone find a solution?
I didn't find anything yet. It is running fine on my local setup but when I run the same on a docker machine, it fails with the above error. @nodkz @AJRdev Please help.
Seeing the same w/ last version, returning to 5.2.5 works 🤔
Seeing the same w/ last version, returning to 5.2.5 works
Thanks @Negan1911
facing this issue as well now^, with replicasets starting from 5.2.5
@sakulstra it worked here:
```const { MongoMemoryReplSet } = require('mongodb-memory-server')
describe('single server replset', () => {
it('should enter running state', async () => {
const replSet = new MongoMemoryReplSet();
await replSet.waitUntilRunning();
const uri = await replSet.getUri();
expect(uri.split(',').length).toEqual(1);
});
});
```
"mongodb-memory-server": "5.2.5",
Using 5.2.5 solved the issue for me.
Make sure your package.json is: "mongodb-memory-server": "5.2.5" instead of "mongodb-memory-server": "^5.2.5".
@clawdaddy You config is almost as ours. We think that it may has something to do with the combination of TypeScript and @shelf/jest-mongodb. ATM we got rid of @shelf/jest-mongodb which is an convenience layer anyways.
It's still not working because of timeouts but this certain error is gone. Everythings running fine when running this package with the suggested config and without TS, even with @shelf/jest-mongodb.
After throwing TS in and making mongodb-memory-server "global" (jestconfig > setup) things getting out of hand.
Another thing: Even though we're async/await-ing everything our mongoose "I'm connected"-message fires on re-run (jest flag --watch), the global setup re-runs (sadly) as well.
Just my 2 cents... :(
EDIT:
@MarceloPrado I can confirm that 5.2.5 doesn't throw the mentioned error with the same config.
Short version:
I'll have an update. It does seem that it may have something to do with MongoDB driver itself.
Maybe the driver should be updated to v. 3.3.3
Longer version:
Initially I came from an issue regarding useUnifiedTopology: true, in the client connecttion settings. After digging deeper (see my previous comment) I landed here.
This is the official MongoDB Bug https://jira.mongodb.org/browse/NODE-2249 and an update has been published. Maybe we can require MongoDB driver with "mongodb": "^3.3.3"but I'm not fully aware whats happening under the hood here. Maybe some of the maintainers can check this.
This error is the result of the driver being unable to connect to a server satisfying the read preference of a given operation (or initial connect). This could be for a number of reasons, including your connection string being invalid or nodes in your cluster being down. If you update to the latest v3.3.3 of the driver we include a new reason field with the MongoTimeoutError which will help us further investigate your issue. Additionally, this version includes a bug fix which would result in a timeout error on initial connect if any member of a replicaset was not available. Please update your driver, and let us know if you continue to experience this issue.
Quoted from https://jira.mongodb.org/browse/NODE-2249?focusedCommentId=2485028&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-2485028
I Quoted from https://github.com/Automattic/mongoose/issues/8180#issuecomment-542848174
@bke-daniel please test the latest v 5.2.11 version with ReplicaSets.
I had crazy MongoClient topology debugging session, after that was introduced such HACK https://github.com/nodkz/mongodb-memory-server/commit/470f09485d5caa9062fc1c24fb5efc0eb3d7d32f
It should help to solve "Error: Maximum call stack size exceeded" for ReplicaSets.
If anybody still have "Error: Maximum call stack size exceeded" for graceful-fs/graceful-fs.js please open a new issue. Cause this issue contains two absolutely different errors with max stack.
Thanks.
Sorry for answering that late @nodkz have been on multiple business trips.
With v5.2.11 the error is gone. Still there's this useUnifiedTopology: true around, but (I guess) it has nothing to do with this one here.
Thank you @nodkz !!
Most helpful comment
Seeing the same w/ last version, returning to 5.2.5 works 🤔