Registry / devops / native-addon-loader

native-addon-loader

JSON →
library2.0.1jsnpmunverified

A webpack loader for bundling .node native addon files. Version 2.0.1 supports configuring output filename and path relative to webpack's output path. It is designed for Node.js or Electron main process targets. Unlike generic file loaders, it ensures .node binaries are emitted intact and correctly referenced in the bundle. Stable API with simple options: 'name' for filename template and 'from' for adjustment of relative path from output directory to emitted file. Last updated in 2021; low maintenance cadence.

npm install native-addon-loader
INSTALL
IMPORT
SIG · NATIVE-ADDON-LOADE
N
native-addon-loader
devopsjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default config
module.exports = { module: { rules: [ { test: /\.node$/, loader: 'native-addon-loader' } ] } }
module.exports = { module: { rules: [ { test: /\.node$/, loader: 'file-loader' } ] } }
The loader is configured as a rule in webpack config, not imported in source code.

Shows how to configure native-addon-loader for a webpack build targeting Node.js, emitting .node files to a subdirectory with a content hash.

// webpack.config.js const path = require('path'); module.exports = { target: 'node', output: { path: path.join(__dirname, 'dist'), filename: 'js/[name].js' }, module: { rules: [ { test: /\.node$/, use: [ { loader: 'native-addon-loader', options: { name: 'addons/[name]-[hash].[ext]', from: 'js' } } ] } ] } };
Debug
Known issues
breakingWebpack 5 may require additional configuration for asset modules.
fix
Use type: 'javascript/auto' in the rule to disable asset module handling for .node files.
affects: >=2.0.0
deprecatedVersion 2.x is the latest and stable.
fix
No action needed; if using older version, upgrade to 2.x.
affects: >=2.0.0
gotchaThe 'from' option is relative to webpack's output path, not the source file location.
fix
Set 'from' to the path where your JavaScript bundles are output relative to output.path (e.g., 'js').
affects: >=2.0.0
Errors
Common errors & fixes
Module parse failed: Unexpected character '\x7f' (1:0)
Webpack is trying to parse the .node file as JavaScript.
fix
Ensure the rule with native-addon-loader has test: /\.node$/ and no other loaders match .node files.
Error: Cannot find module './path/to/addon.node'
The emitted .node file is not in the expected output directory.
fix
Check the 'name' option matches the require path in your code. Use name: '[name].[ext]' to keep the same filename.
TypeError: loaderContext.getOptions is not a function
Using an older version of webpack (before 4.x) that doesn't support getOptions.
fix
Upgrade to webpack 4 or 5, or use native-addon-loader@1.x for webpack < 4.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
webpackrequiredPeer dependency; loader is used within webpack build pipeline.
Agent activity
2 hits · last 30 days
node
2
Resources
native-addon-loader — npm install native-addon-loader · libregistry