mongodb-memory-server: Mongod binary installing in the wrong directory of workspace PNPM

Versions

  • NodeJS: 14.16.1
  • mongodb-memory-server-*: 7.0.0-beta.49
  • mongodb(the binary version): 4.0.25
  • mongoose: 5.12.15
  • system: Windows 10

package: mongo-memory-server

What is the Problem?

MMS = mongodb-memory-server

I use MMS in a package of workspace and after installing dependencies and running a test script in the package, MMS tries to download the binary file. But if I run the test command from the root folder of the workspace, MMS can find the binary file from node_modules/.cache folder.

What I mean by root directory is: C:\Users\Sahin\projects\temp\mongodb-memory-server-issue-x And what I meant by package directory is: C:\Users\Sahin\projects\temp\mongodb-memory-server-issue-x\packages\my-app

Here is the folder structure: image

Code Example

Here is the minimal repo https://github.com/seahindeniz/mongodb-memory-server-issue-489

Do you know why it happenes?

I’m not sure why, but I guess postinstall script installs the binary file to the upper node_modules folder rather than installing to the closest node_modules folder and using it from the closest node_modules. I guess it should work respectfully

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17

Most upvoted comments

closing, because workaround (PREFER_GLOBAL_PATH) works and wontfix label

I understand that MongoMS is now downloading and using the binary from temp folder- which I assume it is the default behavior of using preferGlobalPath option.

like i said earlier, this temporary directory is only for the DataBase Path, not the Binary or Download path

and preferGlobalPath will install it into the current users home directory (on POSIX systems, its ~/.cache/mongodb-binaries, and on DOS systems, its %USERPROFILE%/.cache/mongodb-binaries - both using os.homedir())

and as you can see by the output of

MongoMS:DryMongoBinary generateDownloadPath: Found binary in legacyHomeCache: "C:\Users\Sahin\.cache\mongodb-binaries\mongod-x64-win32-4.0.25.exe" +18ms

the binary is stored at C:\Users\Sahin\.cache\mongodb-binaries\mongod-x64-win32-4.0.25.exe

I tried setting the downloadDir config in the projectRoot/package.json:

DOWNLOAD_DIR option is meant to be absolute, but if its not, then its implicitly resolved with process.cwd(), which can be very wrong in an install

apparently it tries to find it in a temp folder, not sure why.

if you mean the message from _startUpInstance: Creating new MongoDB instance with options:, then no, this package creates an temporary directory (in the system’s temp folder) to the database to use (mongod --dbPath option)

I have run test command with debug variable while the preferGlobalPath config is set to true:

could you provide how you have set this? because it seems to have thrown an very weird error somehow (an value was not an string, where it should always have been an string, fixed with beta 50)

I have terminated the test process, because no need to wait for it to be downloaded again since test process will timeout and fail.

btw, if you want you can set RUNTIME_DOWNLOAD to false, and it will error out instead of trying to download on runtime


beta 50 should be released soon (~10min), which includes some fixes i noticed from the logs

PS: thanks to the reproduction repo, i will now try to use pnpm and the repo in an VM