{"id":22142,"library":"rollup-plugin-natives","title":"rollup-plugin-natives","description":"A Rollup plugin that extracts native .node files from the bundle and copies them to a specified directory, with options for renaming, mapping, and using dlopen or createRequire for ESM. Current stable version is 0.7.8. Released on npm, maintained by @danielgindi. Differentiates from other Rollup native module plugins by supporting node-pre-gyp and bindings integration, providing originTransform for dynamic path resolution, and offering flexible copying and naming via map functions.","status":"active","version":"0.7.8","language":"javascript","source_language":"en","source_url":"https://github.com/danielgindi/rollup-plugin-natives","tags":["javascript"],"install":[{"cmd":"npm install rollup-plugin-natives","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-natives","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-natives","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency >=0.56.0","package":"rollup","optional":false}],"imports":[{"note":"CommonJS require works but ESM import is recommended.","wrong":"const nativePlugin = require('rollup-plugin-natives');","symbol":"default (plugin function)","correct":"import nativePlugin from 'rollup-plugin-natives';"},{"note":"No named export exists; use default import.","wrong":"import { nativePlugin } from 'rollup-plugin-natives';","symbol":"plugin function (named)","correct":"import { default as nativePlugin } from 'rollup-plugin-natives';"},{"note":"Options type must be imported with type-only import to avoid value import in TS.","wrong":"import { Options } from 'rollup-plugin-natives';","symbol":"TypeScript types","correct":"import type { Options } from 'rollup-plugin-natives';"}],"quickstart":{"code":"// rollup.config.js\nimport nativePlugin from 'rollup-plugin-natives';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    file: 'dist/bundle.js',\n    format: 'cjs'\n  },\n  plugins: [\n    nativePlugin({\n      copyTo: 'dist/libs',\n      destDir: './libs',\n      dlopen: false,\n      targetEsm: false,\n      sourcemap: true\n    })\n  ]\n};\n","lang":"javascript","description":"Basic Rollup config that extracts native .node files to dist/libs and rewrites requires to point there."},"warnings":[{"fix":"Ensure all native module requires are static strings, or use originTransform to map dynamic paths.","message":"Plugin does not handle dynamic require() of .node files that are not statically analyzable.","severity":"gotcha","affected_versions":"all"},{"fix":"Set destDir relative to the output file location (e.g., './libs' if bundle is in 'dist').","message":"destDir is relative to the output bundle, not to the project root.","severity":"gotcha","affected_versions":"all"},{"fix":"Set dlopen: true when working with .node files that have a different extension.","message":"dlopen option must be true if using a file extension other than .node.","severity":"gotcha","affected_versions":"all"},{"fix":"Set targetEsm: true when output format is 'esm' or 'es'.","message":"targetEsm option is required for ESM output; without it, createRequire is not used and imports fail.","severity":"gotcha","affected_versions":">=0.7.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Verify copyTo and destDir paths, ensure the plugin runs before bundle generation.","cause":"Plugin didn't copy the .node file or destDir is incorrect.","error":"Error: Cannot find module './binding.node'"},{"fix":"Set dlopen: false or ensure the module supports dlopen.","cause":"dlopen option set to true but the native module expects require().","error":"TypeError: dlopen is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}