Registry / devops / rollup-plugin-natives

rollup-plugin-natives

JSON →
library0.7.8jsnpmunverified

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.

npm install rollup-plugin-natives
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-NATI
R
rollup-plugin-natives
devopsjavascriptv0.7.8
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin function)
✓ import nativePlugin from 'rollup-plugin-natives';
✗ const nativePlugin = require('rollup-plugin-natives');
CommonJS require works but ESM import is recommended.
plugin function (named)
✓ import { default as nativePlugin } from 'rollup-plugin-natives';
✗ import { nativePlugin } from 'rollup-plugin-natives';
No named export exists; use default import.
TypeScript types
✓ import type { Options } from 'rollup-plugin-natives';
✗ import { Options } from 'rollup-plugin-natives';
Options type must be imported with type-only import to avoid value import in TS.

Basic Rollup config that extracts native .node files to dist/libs and rewrites requires to point there.

// rollup.config.js import nativePlugin from 'rollup-plugin-natives'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'cjs' }, plugins: [ nativePlugin({ copyTo: 'dist/libs', destDir: './libs', dlopen: false, targetEsm: false, sourcemap: true }) ] };
Debug
Known issues
gotchaPlugin does not handle dynamic require() of .node files that are not statically analyzable.
fix
Ensure all native module requires are static strings, or use originTransform to map dynamic paths.
affects: all
gotchadestDir is relative to the output bundle, not to the project root.
fix
Set destDir relative to the output file location (e.g., './libs' if bundle is in 'dist').
affects: all
gotchadlopen option must be true if using a file extension other than .node.
fix
Set dlopen: true when working with .node files that have a different extension.
affects: all
gotchatargetEsm option is required for ESM output; without it, createRequire is not used and imports fail.
fix
Set targetEsm: true when output format is 'esm' or 'es'.
affects: >=0.7.0
Errors
Common errors & fixes
Error: Cannot find module './binding.node'
Plugin didn't copy the .node file or destDir is incorrect.
fix
Verify copyTo and destDir paths, ensure the plugin runs before bundle generation.
TypeError: dlopen is not a function
dlopen option set to true but the native module expects require().
fix
Set dlopen: false or ensure the module supports dlopen.
Upgrade
Version history
0.7.8latest on npm
Audit
Dependencies
rolluprequiredpeer dependency >=0.56.0
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
rollup-plugin-natives — npm install rollup-plugin-natives · libregistry