-
Type: Bug
-
Resolution: Fixed
-
Priority: Blocker - P1
-
Affects Version/s: 4.0.0
-
Component/s: Shell
-
None
We cannot connect to anything using the driver when it's bundled because it will fail with:
MongoServerSelectionError: The 'driver.version' field must be a string in the client metadata document
Because it appears the compiled driver cannot find the package.json file here: https://github.com/mongodb/node-mongodb-native/blob/4f9d4ceafdcca01d49e6eeb286a9c27ddf485969/src/utils.ts#L953-L955.
For mongosh, we use parcel, for which __dirname is not accessible.
A related problem also happens when we try to use the driver with the VSCode extension, in which we get
Uncaught Error: ENOENT: no such file or directory, open '/package.json'
because for webpack __dirname is accessible, but you cannot use read file sync and expect the file to be included in the bundle.
Would it be possible to find a solution that doesn't require getting the version using a file read? A straightforward solution would be in a prebuild step, a version.ts file could be generated that would be usable by bundlers like webpack or parcel. An alternative is using
require('../package.json')
- is depended on by
-
MONGOSH-467 Update driver to 4.0
- Closed