{"id":20227,"library":"native-addon-loader","title":"native-addon-loader","description":"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.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/toyobayashi/native-addon-loader","tags":["javascript"],"install":[{"cmd":"npm install native-addon-loader","lang":"bash","label":"npm"},{"cmd":"yarn add native-addon-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add native-addon-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; loader is used within webpack build pipeline.","package":"webpack","optional":false}],"imports":[{"note":"The loader is configured as a rule in webpack config, not imported in source code.","wrong":"module.exports = { module: { rules: [ { test: /\\.node$/, loader: 'file-loader' } ] } }","symbol":"default config","correct":"module.exports = { module: { rules: [ { test: /\\.node$/, loader: 'native-addon-loader' } ] } }"}],"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nmodule.exports = {\n  target: 'node',\n  output: {\n    path: path.join(__dirname, 'dist'),\n    filename: 'js/[name].js'\n  },\n  module: {\n    rules: [\n      {\n        test: /\\.node$/,\n        use: [\n          {\n            loader: 'native-addon-loader',\n            options: {\n              name: 'addons/[name]-[hash].[ext]',\n              from: 'js'\n            }\n          }\n        ]\n      }\n    ]\n  }\n};","lang":"javascript","description":"Shows how to configure native-addon-loader for a webpack build targeting Node.js, emitting .node files to a subdirectory with a content hash."},"warnings":[{"fix":"Use type: 'javascript/auto' in the rule to disable asset module handling for .node files.","message":"Webpack 5 may require additional configuration for asset modules.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"No action needed; if using older version, upgrade to 2.x.","message":"Version 2.x is the latest and stable.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Set 'from' to the path where your JavaScript bundles are output relative to output.path (e.g., 'js').","message":"The 'from' option is relative to webpack's output path, not the source file location.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure the rule with native-addon-loader has test: /\\.node$/ and no other loaders match .node files.","cause":"Webpack is trying to parse the .node file as JavaScript.","error":"Module parse failed: Unexpected character '\\x7f' (1:0)"},{"fix":"Check the 'name' option matches the require path in your code. Use name: '[name].[ext]' to keep the same filename.","cause":"The emitted .node file is not in the expected output directory.","error":"Error: Cannot find module './path/to/addon.node'"},{"fix":"Upgrade to webpack 4 or 5, or use native-addon-loader@1.x for webpack < 4.","cause":"Using an older version of webpack (before 4.x) that doesn't support getOptions.","error":"TypeError: loaderContext.getOptions is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}