Skip to content

Error: spawn /home/app/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.0.3/mongod ENOENT #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
machadogj opened this issue Apr 15, 2019 · 11 comments
Labels
stale This Issue is outdated and will likely be closed if no further comments are given

Comments

@machadogj
Copy link

machadogj commented Apr 15, 2019

Hello, I have the following code in a mocha test setup file:

before(async function() {
  this.timeout(0);
  const mongod = new MongoMemoryServer({ debug: true });
  const uri = await mongod.getConnectionString();
})

Works well locally, but in circleCI it fails with:

Autostarting MongoDB instance...
Called MongoMemoryServer.start() method:
Called MongoMemoryServer.ensureInstance() method:
Starting MongoDB instance with following options: {"port":42817,"dbName":"5a1789ec-a9a4-4a74-8dc2-c69739468657","uri":"mongodb://127.0.0.1:42817/5a1789ec-a9a4-4a74-8dc2-c69739468657","storageEngine":"ephemeralForTest","dbPath":"/tmp/mongo-mem-68JtuJPtpruwrZ","tmpDir":{"name":"/tmp/mongo-mem-68JtuJPtpruwrZ"}}
MongoBinary options: {"downloadDir":"/home/app/node_modules/.cache/mongodb-memory-server/mongodb-binaries","platform":"linux","arch":"x64","version":"4.0.3"}
MongoBinary: Mongod binary path: /home/app/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.0.3/mongod
Mongo[42817]: Called MongoInstance._launchKiller(parent: 68, child: undefined):
Mongo[42817]: MongodbInstance: is failed: Error: spawn /home/app/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.0.3/mongod ENOENT
  1) "before all" hook in "{root}"
Unhandled rejection TypeError: Cannot read property 'toString' of undefined
    at MongoInstance._launchKiller (node_modules/mongodb-memory-server/lib/util/MongoInstance.js:216:22)

I looked the code at that line and it's the following:

MongoInstance.prototype._launchKiller = function (parentPid, childPid) {
    var _this = this;
    this.debug("Called MongoInstance._launchKiller(parent: " + parentPid + ", child: " + childPid + "):");
    // spawn process which kills itself and mongo process if current process is dead
    var killer = child_process_1.spawn(process.argv[0], [
        path_1.default.resolve(__dirname, '../../scripts/mongo_killer.js'),
        parentPid.toString(),
        childPid.toString(),; // <-- HERE
    ])
}

Any ideas? Thanks!

@machadogj machadogj changed the title Error downloading binary: Cannot read property 'toString' of undefined at MongoInstance._launchKiller Error: spawn /home/app/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.0.3/mongod ENOENT Apr 15, 2019
@machadogj
Copy link
Author

I was able to reproduce this locally by building the docker image, and I can see that the mongod file is there:

docker run api-test ls /home/app/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.0.3/
mongod

@Seao
Copy link

Seao commented Apr 16, 2019

I have the same issue with Gitlab runners using [email protected]

Called MongoInstance._launchKiller(parent: 117, child: undefined):
Mongo[46071]: MongodbInstance: is failed: Error: spawn /builds/lab/apostrophe-modules/project-templates/module/node_modules/.cache/mongodb-memory-server/mongodb-binaries/4.0.3/mongod ENOENT
...

No such file or directory error while Mongodb binaries are well downloaded and saved at this exact path during npm install.. 🤔

@machadogj
Copy link
Author

@Seao in my case was the fact that we were using alpine, which the getos package reports as raspbian, and so it download a legacy binary which doesn't seem to work (and throws the ENOENT error).

What I did in my case, was to download and install mongodb in my docker image and set the MONGOMS_SYSTEM_BINARY environment variable. Here's the code in case you want to give it a try:

RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/main' >> /etc/apk/repositories
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.9/community' >> /etc/apk/repositories
RUN apk update
# mongodb installation throws an error, but seems to work, so ignoring the exit status.
RUN apk add mongodb=4.0.5-r0 || true
# this is required by mongodb-memory-server to avoid trying to download the mongod file.
ENV MONGOMS_SYSTEM_BINARY=/usr/bin/mongod

Hope it helps! If it is for me, we can close this issue 👍

@Seao
Copy link

Seao commented Apr 17, 2019

@machadogj Thanks for the advice, indeed it was related to alpine:3.8 I was using. The thing is, it was implicitly inherited but not relevant at all, so I simply switched to a node:8 image, that is working like a charm 👍

@Yaty
Copy link

Yaty commented Apr 19, 2019

Thanks @machadogj ! You saved my day :)

@sibelius
Copy link

what is the best package to enable cache on circleci?

what is the best strategy to cache this?

@nodkz
Copy link
Collaborator

nodkz commented Jun 25, 2019

@sibelius better to use mongodb-memory-server-global package and add to ci cache the following folder %HOME%/.cache

@sibelius
Copy link

sibelius commented Jul 1, 2019

it would be helpful to have a section in docs like this one https://docusaurus.io/docs/en/publishing#automating-deployments-using-continuous-integration

where you provide a sample setup for circleci, travis and so on

@hasezoey
Copy link
Member

in ~6.1 changed GETOS to an internal re-write, which needs either lsb_release (command) or /etc/os-release file or /etc/*-release (any -release (that is not lsb) file) - so it should work for alpine now (because alpine uses /etc/os-release) BUT mongodb DOES NOT support alpine!

i will close this because (thanks to the getos re-write) it should now detect the right system, but because mongodb dosnt provide a binary for alpine it is still recommended to use a node image

@IlmariKu
Copy link

I had this issue at Gitlab, was fixed without other configuration changes simply by just changing the image to the non-alpine one.

From:

test:
  image: node:15-alpine
  

To:

 test:
  image: node:15

@adoidadox2
Copy link

I had this issue at Gitlab, was fixed without other configuration changes simply by just changing the image to the non-alpine one.

From:

test:
  image: node:15-alpine
  

To:

 test:
  image: node:15

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This Issue is outdated and will likely be closed if no further comments are given
Projects
None yet
Development

No branches or pull requests

8 participants