{"id":42473,"library":"bson-ext","title":"bson-ext","description":"A C++ native addon for BSON serialization/deserialization, used as a faster alternative to the pure JavaScript js-bson library. Version 4.0.3 is the latest stable release, compatible with js-bson v4+ and the MongoDB Node.js driver v4+. The package has irregular release cadence and is now deprecated in favor of the pure JavaScript js-bson library, which eliminates native compilation issues and provides better cross-platform support. It is only for Node.js (not browser) and uses N-API for native bindings.","status":"deprecated","version":"4.0.3","language":"javascript","source_language":"en","source_url":"git://github.com/mongodb-js/bson-ext","tags":["javascript","mongodb","bson","parser"],"install":[{"cmd":"npm install bson-ext","lang":"bash","label":"npm"},{"cmd":"yarn add bson-ext","lang":"bash","label":"yarn"},{"cmd":"pnpm add bson-ext","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides core BSON types and serialization logic; bson-ext replaces the pure JS implementation with a native addon for performance.","package":"bson","optional":false}],"imports":[{"note":"bson-ext is not ESM-compatible; only CommonJS require works.","wrong":"import BSON from 'bson-ext'","symbol":"BSON","correct":"const BSON = require('bson-ext')"},{"note":"Long is a property on the BSON object, not a named export.","wrong":"const { Long } = require('bson-ext')","symbol":"Long","correct":"const Long = require('bson-ext').Long"},{"note":"ObjectId is exported from bson-ext, not the bson package.","wrong":"const ObjectId = require('bson').ObjectId","symbol":"ObjectId","correct":"const ObjectId = require('bson-ext').ObjectId"}],"quickstart":{"code":"const BSON = require('bson-ext');\nconst Long = BSON.Long;\n\n// Create a document with a Long type\nconst doc = { long: Long.fromNumber(100) };\n\n// Serialize to BSON buffer\nconst data = BSON.serialize(doc);\nconsole.log('Serialized BSON:', data);\n\n// Deserialize back\nconst deserialized = BSON.deserialize(data);\nconsole.log('Deserialized:', deserialized);","lang":"javascript","description":"Demonstrates serialization and deserialization using deprecated bson-ext native addon with CommonJS."},"warnings":[{"fix":"Replace 'bson-ext' with 'bson' in package.json and require statements: const BSON = require('bson');","message":"bson-ext is deprecated; use js-bson (the 'bson' package) instead.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Ensure all dependencies are updated to v4+.","message":"v4.0.0+ requires js-bson v4+ and MongoDB driver v4+; incompatible with older versions.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use js-bson which is pure JavaScript and has no native dependencies.","message":"bson-ext is a native addon requiring build tools (e.g., python, make) and may fail on some platforms.","severity":"gotcha","affected_versions":"all"},{"fix":"Use require('bson-ext') instead of import.","message":"ESM imports (import/export) are not supported; only CommonJS require works.","severity":"gotcha","affected_versions":"all"},{"fix":"Update serialization options to exclude removed tokens.","message":"The token-based serialization options were removed in v4.0.0; only checkKeys, serializeFunctions, ignoreUndefined are supported.","severity":"breaking","affected_versions":">=4.0.0"}],"env_vars":null,"search_vec":"'4.0.3':25 'addon':7 'altern':15 'api':86 'better':70 'bind':89 'browser':81 'bson':2,9,22,35,61,92 'bson-ext':1 'c':5 'cadenc':48 'compat':31 'compil':66 'cross':72 'cross-platform':71 'deprec':52 'driver':41 'elimin':64 'ext':3 'faster':14 'favor':54 'irregular':46 'issu':67 'javascript':19,58,90 'js':21,34,60 'js-bson':20,33,59 'latest':28 'librari':23,62 'mongodb':39,91 'n':85 'n-api':84 'nativ':6,65,88 'node.js':40,79 'packag':44 'parser':93 'platform':73 'provid':69 'pure':18,57 'releas':30,47 'serialization/deserialization':10 'stabl':29 'support':74 'use':11,83 'v4':36,42 'version':24","created_at":"2026-06-05T16:55:09.884980+00:00","updated_at":"2026-06-05T16:55:09.884980+00:00","problems":[{"fix":"Rebuild bson-ext against your Node.js version: npm rebuild bson-ext or switch to 'bson'.","cause":"Native addon compiled for a different Node.js version.","error":"Error: The module 'bson-ext' was compiled against a different Node.js version using NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 70."},{"fix":"Install bson-ext: npm install bson-ext. Use require('bson-ext'), not import.","cause":"Missing or incorrectly imported package.","error":"Module not found: Error: Can't resolve 'bson-ext'"},{"fix":"Use const BSON = require('bson-ext'); then BSON.serialize(doc).","cause":"Using default import instead of require, or package not properly required.","error":"TypeError: BSON.serialize is not a function"},{"fix":"Try npm rebuild bson-ext or switch to js-bson (bson package).","cause":"Native addon build artifacts missing or incompatible platform.","error":"Error: Cannot find module '../build/Release/bson'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/mongodb-js/bson-ext#readme","github":"git://github.com/mongodb-js/bson-ext","docs":null,"changelog":null,"pypi":null,"npm":"bson-ext","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}