{"id":22141,"library":"rollup-plugin-native","title":"rollup-plugin-native","description":"A Rollup plugin that enables importing native .node modules (N-API addons) by resolving platform-specific binary paths during bundling. Version 1.2.16, last updated in 2024, with low release cadence (no breaking changes in recent versions). It uses substitution patterns like ${nodePlatform} and ${nativeArchitecture} to dynamically select the correct precompiled binary for the current OS/arch, avoiding the need for node-gyp at runtime. Differentiators: simplifies cross-platform native module bundling without manual conditional requires, and integrates directly into Rollup's plugin system. No other known alternative for Rollup-focused native module import.","status":"active","version":"1.2.16","language":"javascript","source_language":"en","source_url":"https://github.com/arlac77/rollup-plugin-native","tags":["javascript","rollup-plugin","native","napi"],"install":[{"cmd":"npm install rollup-plugin-native","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-native","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-native","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only package; CommonJS require() will work but is not recommended for Rollup configs.","wrong":"const native = require('rollup-plugin-native')","symbol":"default (native)","correct":"import native from 'rollup-plugin-native'"},{"note":"The plugin exports a default function, not a named export. Use default import.","wrong":"import { native } from 'rollup-plugin-native'","symbol":"native","correct":"import native from 'rollup-plugin-native'"},{"note":"TypeScript types may not be shipped; use JSDoc or custom type definitions.","wrong":"undefined","symbol":"RollupPluginNativeOptions","correct":"/** @type {import('rollup-plugin-native').PluginOptions} */"}],"quickstart":{"code":"// rollup.config.js\nimport native from 'rollup-plugin-native';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'cjs'\n  },\n  plugins: [\n    native({\n      platformName: 'precompiled/${nodePlatform}-${nodeArchitecture}/native.node'\n    })\n  ]\n};","lang":"javascript","description":"Configures Rollup to resolve native .node modules with platform-specific binary paths using substitution variables."},"warnings":[{"fix":"Use output.format: 'cjs' instead of 'cfs'.","message":"Format 'cfs' in documentation is a typo; use 'cjs' for CommonJS output.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure output format is 'cjs' when using native modules, or use plugin options to generate conditional require.","message":"Dynamic require of .node files may not work in all Rollup output formats (e.g., esm).","severity":"gotcha","affected_versions":"all"},{"fix":"Use ${basename} without .node in the path template, as the extension is handled internally.","message":"Substitution ${basename} strips .node extension; ensure paths are correct.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Upgrade Rollup to version 3 or later.","message":"The plugin only supports Rollup >=3.0.0; older versions may fail.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Verify platformName template resolves correctly; check process.platform() and process.arch() values.","cause":"platformName pattern does not match the actual file path","error":"Error: Cannot find module '../module.node'"},{"fix":"Use default import: import native from 'rollup-plugin-native'","cause":"Named import used instead of default import","error":"TypeError: native is not a function"},{"fix":"Pass an options object with a 'platformName' property to native().","cause":"Plugin instantiated without options but platformName is required","error":"(!) Plugin native: Options object is required"},{"fix":"Upgrade Rollup to 3.x or later: npm install rollup@latest --save-dev","cause":"Using an older version of Rollup","error":"Error: Rollup plugin native requires Rollup >=3.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}