{"id":"ac4ab11bac23cae3","repo":"mongodb/node-mongodb-native","slug":"auto-encryption-requested-but-the-module-is-not-i","errorCode":null,"errorMessage":"Auto-encryption requested, but the module is not installed. Please add `mongodb-client-encryption` as a dependency of your project","messagePattern":"Auto-encryption requested, but the module is not installed\\. Please add `mongodb-client-encryption` as a dependency of your project","errorType":"exception","errorClass":"MongoMissingDependencyError","httpStatus":null,"severity":"critical","filePath":"src/encrypter.ts","lineNumber":117,"sourceCode":"    let error;\n    try {\n      await this.autoEncrypter.close();\n    } catch (autoEncrypterError) {\n      error = autoEncrypterError;\n    }\n    const internalClient = this.internalClient;\n    if (internalClient != null && client !== internalClient) {\n      return await internalClient.close();\n    }\n    if (error != null) {\n      throw error;\n    }\n  }\n\n  static checkForMongoCrypt(): void {\n    const mongodbClientEncryption = getMongoDBClientEncryption();\n    if ('kModuleError' in mongodbClientEncryption) {\n      throw new MongoMissingDependencyError(\n        'Auto-encryption requested, but the module is not installed. ' +\n          'Please add `mongodb-client-encryption` as a dependency of your project',\n        {\n          cause: mongodbClientEncryption['kModuleError'],\n          dependencyName: 'mongodb-client-encryption'\n        }\n      );\n    }\n  }\n}\n","sourceCodeStart":99,"sourceCodeEnd":128,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/encrypter.ts#L99-L128","documentation":"Client-Side Field Level Encryption (CSFLE) requires the native mongodb-client-encryption package which wraps libmongocrypt. When autoEncryption is enabled but the package cannot be loaded, the driver throws MongoMissingDependencyError at client construction. The native binary must match the runtime platform.","triggerScenarios":"Enabling autoEncryption on MongoClient without installing mongodb-client-encryption; production deploy missing the optional dependency; native binary/Node ABI mismatch.","commonSituations":"Forgetting to add the dependency; CI cache miss; ARM/glibc/musl binary mismatch; upgrading Node without rebuilding native modules.","solutions":["Run npm install mongodb-client-encryption and add it to package.json dependencies","Rebuild native modules after Node version changes (npm rebuild)","Ensure the deployment image provides a compatible libmongocrypt runtime","If CSFLE was unintended, remove the autoEncryption option entirely"],"exampleFix":"// before\n// package.json has no mongodb-client-encryption\nnew MongoClient(uri, { autoEncryption: { /* ... */ } });\n// after\n// npm install mongodb-client-encryption\nnew MongoClient(uri, { autoEncryption: { /* ... */ } });","handlingStrategy":"validation","validationCode":"function assertEncryptionModule() {\n  try {\n    require('mongodb-client-encryption');\n  } catch {\n    throw new Error('Run: npm install mongodb-client-encryption');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  client = await MongoClient.connect(uri, { autoEncryption });\n} catch (err) {\n  if (err?.dependencyName === 'mongodb-client-encryption') {\n    // fail fast with an actionable deploy message\n    throw new Error('Missing native dep; run npm install mongodb-client-encryption');\n  }\n  throw err;\n}","preventionTips":["Add mongodb-client-encryption to package.json dependencies","Smoke-test module load at container boot","Pin Node version to match the native module prebuilds","Run npm rebuild after Node upgrades"],"tags":["encryption","csfle","dependency","native-module","deployment"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}