{"record":{"id":"49b3eda20a51175c","repo":"neon-bindings/neon","slug":"failed-to-find-n-api-version","errorCode":null,"errorMessage":"Failed to find N-API version","messagePattern":"Failed to find N-API version","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/neon/src/sys/bindings/functions.rs","lineNumber":458,"sourceCode":"// This symbol is loaded separately because it is a prerequisite\nunsafe fn get_version(host: &libloading::Library, env: Env) -> Result<u32, libloading::Error> {\n    let get_version = host.get::<fn(Env, *mut u32) -> Status>(b\"napi_get_version\")?;\n    let mut version = 0;\n\n    assert_eq!(get_version(env, &mut version as *mut _), Status::Ok,);\n\n    Ok(version)\n}\n\npub(crate) unsafe fn load(env: Env) -> Result<(), libloading::Error> {\n    #[cfg(not(windows))]\n    let host = libloading::os::unix::Library::this().into();\n    #[cfg(windows)]\n    let host = libloading::os::windows::Library::this()?.into();\n\n    // This never fail since `get_version` is in N-API Version 1 and the module will fail\n    // with `Error: Module did not self-register` if N-API does not exist.\n    let actual_version = get_version(&host, env).expect(\"Failed to find N-API version\");\n\n    let expected_version = match () {\n        _ if cfg!(feature = \"napi-8\") => 8,\n        _ if cfg!(feature = \"napi-7\") => 7,\n        _ if cfg!(feature = \"napi-6\") => 6,\n        _ if cfg!(feature = \"napi-5\") => 5,\n        _ if cfg!(feature = \"napi-4\") => 4,\n        _ if cfg!(feature = \"napi-3\") => 3,\n        _ if cfg!(feature = \"napi-2\") => 2,\n        _ => 1,\n    };","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/neon-bindings/neon/blob/38960e4381d9ad13b551cdf2d261f609167c9bc2/crates/neon/src/sys/bindings/functions.rs#L440-L476","documentation":"During symbol loading, `napi_get_version` was resolved from the host library via libloading, but the call either failed to load the symbol or did not return Status::Ok, so the Node-API version reported by the running Node process could not be determined. This indicates the module is not running inside a Node-API-capable host (e.g. loaded by a non-Node process) or a broken libloading resolution.","triggerScenarios":"`load` runs when the native module is registered; it panics if `get_version` cannot resolve `napi_get_version` from the host process or the call returns a status other than Status::Ok — i.e. the host has no Node-API support.","commonSituations":"Native module loaded outside of Node.js (e.g. from another FFI host); a Node binary so old it lacks N-API; corrupted/incompatible libloading setup on Windows where `Library::this()` itself fails.","solutions":["Run the module under a Node.js version that supports Node-API (napi_get_version is available since Node 10+ / all N-API-capable releases)","Do not load the .node addon via dlopen/LoadLibrary from non-Node host processes","On Windows, ensure the module is loaded through the normal require() path so Library::this() resolves the host correctly","Check `Error: Module did not self-register` cases — the module may have been linked against a host without N-API"],"exampleFix":"Load the addon with a supported Node.js runtime (Node >= the version matching the crate's napi feature); do not dlopen the .node addon from non-Node processes.","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare and test against a minimum Node.js version in CI","Pin the napi-* feature of neon to match the oldest Node version you support"],"tags":[],"backgroundTag":null,"analyzedSha":"38960e4381d9ad13b551cdf2d261f609167c9bc2","analyzedAt":"2026-09-13T09:05:33.640Z","contentChangedAt":"2026-09-13T09:05:33.640Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}