-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 7.6.0
-
Component/s: Connection Establishment
-
1
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Expected Behavior
As a... Node Driver developer
I expect... driver to load correctly when `require` is available but dynamic-import callback is not
When... using driver 7.6 or higher
Actual Behavior and Impact
- Current experience: `MongoServerError: Missing required sub-document 'driver' in the client metadata document`
- This is incorrect and a red herring, forcing a user on a useless investigation
- Workaround: setting `runtimeAdapters: { os: require('os') }` as a connection option
Dependencies
- none
Risks/Unknowns
- none
Acceptance Criteria
Implementation Requirements
- update resolveRuntimeAdapters so it doesn't throw under environment where `require` is available, but the dynamic-import callback is not, like jest
- `resolveRuntimeAdapters` resolves the default `os` adapter in a host that provides
`require` but no dynamic-import callback. - `resolveRuntimeAdapters` still resolves where `require` is absent or throws: real ESM,
bundled ESM output, and the nodeless sandbox. - A failure to build client metadata is no longer converted into an empty metadata document.
Testing Requirements
- add a new regression test that fails before the change
- new test must exercise a host that provides `require` but not a dynamic-import callback
- existing tests keep passing
Documentation Requirements
- none
Follow Up Requirements
- none
Old text
Some users (myself included) noticed a new error upon upgrading to client version `7.6.0`, namely: `MongoServerError: Missing required sub-document 'driver' in the client metadata document`.
This has been tracked down to [PR 4992](https://github.com/mongodb/node-mongodb-native/pull/4992) being the cause, with [this comment](https://github.com/mongodb/node-mongodb-native/pull/4992#issuecomment-5436379987) being the first one to report the issue.
Additionally, this has been reported to me at https://github.com/typegoose/mongodb-memory-server/issues/1026.
Workaround: set `runtimeAdapters: { os: require('os') }` as a connection option