-
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.