-
Type: Task
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
dot-i has created PR #643: fix: use Symbol.for('id') in ObjectId to fix errors when mixing cjs and mjs in js-bson
Fix interoperability of bson between ESM and CommonJS.
What is changing?
Symbol('id') is replaced with Symbol.for('id') in objectid.ts. This avoids the issue of two different symbols being used for ESM and CommonJS, causing ObjectId.equals() to fail with an undefined error.
Is there new documentation needed for these changes?
No.
What is the motivation for this change?
We are switching our modules to be ESM and ran in to this issue because we imported bson directly from our module (ESM), but also sometimes through a CommonJS import which in turn also imported bson – but as CommonJS module.
This caused ObjectId.equals() to fail since there were two separate 'id' symbols in use, causing an undefined error.
- fixes
-
NODE-5756 ObjectId instances created by bson and mongodb are not interchangeable
- Closed
- is duplicated by
-
NODE-5872 ObjectId.equals throws vague error two bson packages are loaded
- Closed
- is related to
-
NODE-6443 instanceof checks don't work when mongodb and bson are used together in ESM project
- Blocked
- related to
-
NODE-5756 ObjectId instances created by bson and mongodb are not interchangeable
- Closed