{"id":27540,"library":"weak-node-api","title":"weak-node-api","description":"A linkable and runtime-injectable Node-API implementation that allows native addons to be built without direct linking against a Node-API provider. Version 0.1.1 is the latest stable release, part of the React Native Node-API project. It is a thin shim that exposes only Node-API function declarations, enabling runtime injection of the actual implementation by the host (e.g., React Native runtime), solving Android dynamic linker symbol resolution issues. Unlike typical Node-API bindings, it decouples addon compilation from the runtime, supporting React Native and potentially other contexts. Dependencies: none. Release cadence: early stage, active development.","status":"active","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/callstackincubator/react-native-node-api","tags":["javascript","react-native","napi","node-api","node-addon-api","native","addon","module","c"],"install":[{"cmd":"npm install weak-node-api","lang":"bash","label":"npm"},{"cmd":"yarn add weak-node-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add weak-node-api","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Renamed from WeakNodeApiHost to NodeApiHost in v0.1.0.","wrong":"import { WeakNodeApiHost } from 'weak-node-api'","symbol":"NodeApiHost","correct":"import { NodeApiHost } from 'weak-node-api'"},{"note":"ESM only; no CommonJS support documented.","wrong":"const NapiMixin = require('weak-node-api').NapiMixin","symbol":"NapiMixin","correct":"import { NapiMixin } from 'weak-node-api'"},{"note":"TypeScript type export, no value runtime.","symbol":"ModuleFunctionMap","correct":"import type { ModuleFunctionMap } from 'weak-node-api'"},{"note":"Named export; default import is not available.","wrong":"import defineNapiModule from 'weak-node-api'","symbol":"defineNapiModule","correct":"import { defineNapiModule } from 'weak-node-api'"}],"quickstart":{"code":"import { NodeApiHost, defineNapiModule, NapiMixin } from 'weak-node-api';\n\n// Define a simple Node-API module\nconst myModule = defineNapiModule({\n  napiVersion: 8,\n  functions: {\n    add: (env, napiValue) => {\n      // implementation placeholder\n      return 42;\n    }\n  } as any\n});\n\n// Create a host that injects the implementation\nconst host = new NodeApiHost({\n  module: myModule,\n  // other options\n});\n\n// Mixin example\nclass MyAddon extends NapiMixin {\n  // NapiMixin provides Node-API context\n}\n\nconsole.log('weak-node-api initialized');","lang":"typescript","description":"Demonstrates creating a NodeApiHost and defining a module with weak-node-api."},"warnings":[{"fix":"Replace WeakNodeApiHost with NodeApiHost.","message":"WeakNodeApiHost class renamed to NodeApiHost in v0.1.0.","severity":"breaking","affected_versions":"<0.1.0"},{"fix":"Use import statements; if in CommonJS project, use dynamic import or switch to ESM.","message":"All exports are ESM-only; there is no CommonJS build. Using require() will fail.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Add these to tsconfig.json: { compilerOptions: { module: 'esnext', moduleResolution: 'bundler', esModuleInterop: true } }","message":"TypeScript users must ensure 'resolveJsonModule' and 'esModuleInterop' are set for proper type support.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Pin exact version and monitor changes.","message":"The package is in early alpha; API may change without major semver bump.","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install the package and ensure tsconfig.json includes 'node' types. If still failing, add 'skipLibCheck': true.","cause":"TypeScript cannot resolve types; likely missing @types or declaration files.","error":"Cannot find module 'weak-node-api' or its corresponding type declarations."},{"fix":"Switch to ES modules (use 'import') or use dynamic import: const weak = await import('weak-node-api');","cause":"Using CommonJS require() on an ESM-only package.","error":"ERR_REQUIRE_ESM: require() of ES Module /node_modules/weak-node-api/index.mjs from <file>.js not supported."},{"fix":"Use NodeApiHost instead.","cause":"Using the old class name WeakNodeApiHost which was renamed in v0.1.0.","error":"TypeError: WeakNodeApiHost is not a constructor."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}