{"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,"search_vec":"'0.7.8':39 'bind':60 'bundl':15 'copi':17,71 'createrequir':32 'current':35 'danielgindi':45 'differenti':46 'directori':22 'dlopen':30 'dynam':65 'esm':34 'extract':9 'file':12 'flexibl':70 'function':76 'gyp':58 'integr':61 'javascript':77 'maintain':43 'map':27,75 'modul':51 'name':73 'nativ':4,10,50 'node':11,56 'node-pre-gyp':55 'npm':42 'offer':69 'option':24 'origintransform':63 'path':66 'plugin':3,7,52 'pre':57 'provid':62 'releas':40 'renam':26 'resolut':67 'rollup':2,6,49 'rollup-plugin-n':1 'specifi':21 'stabl':36 'support':54 'use':29 'version':37 'via':74","created_at":"2026-04-27T17:03:36.890923+00:00","updated_at":"2026-04-27T17:03:36.890923+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/danielgindi/rollup-plugin-natives","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/rollup-plugin-natives","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-18","next_check":"2026-07-26","install_tag":null}}