{"id":12854,"library":"awesome-node-loader","title":"Webpack Node Native Loader","description":"awesome-node-loader is a webpack loader designed to correctly bundle and handle Node.js native addon files, typically with a `.node` extension, within a webpack build process. It is currently at version 1.1.1 and explicitly supports webpack v4. The package appears to be in maintenance mode, with no recent releases indicating active development for newer webpack versions (v5+). Its primary purpose is to ensure that native modules, which are often pre-compiled C++ addons, are properly copied to the output directory and their paths are correctly resolved at runtime, preventing common 'module not found' errors. Key differentiators include its focus on native modules, which is crucial for applications built with frameworks like Electron or when bundling for environments that rely on specific native dependencies, allowing developers to embed these dependencies rather than requiring them to be present in the target environment's Node Modules.","status":"maintenance","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/gurisko/awesome-node-loader","tags":["javascript","webpack","loader","node","native","electron","aws","pkg"],"install":[{"cmd":"npm install awesome-node-loader","lang":"bash","label":"npm"},{"cmd":"yarn add awesome-node-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add awesome-node-loader","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This loader is configured as a string within webpack's `module.rules` array. There are no direct JavaScript imports or requires for this package in application code.","symbol":"awesome-node-loader","correct":"module.exports = {\n  // ...\n  module: {\n    rules: [\n      {\n        test: /\\.node$/,\n        loader: 'awesome-node-loader'\n      }\n    ]\n  }\n};"},{"note":"Loader options are passed as an object within the `rules` configuration.","symbol":"options","correct":"module.exports = {\n  // ...\n  module: {\n    rules: [\n      {\n        test: /\\.node$/,\n        loader: 'awesome-node-loader',\n        options: {\n          name: '[name].[ext]',\n          rewritePath: 'dist/native_modules'\n        }\n      }\n    ]\n  }\n};"}],"quickstart":{"code":"const path = require('path');\n\nmodule.exports = {\n  mode: 'production',\n  target: 'node',\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n  module: {\n    rules: [\n      {\n        test: /\\.node$/,\n        loader: 'awesome-node-loader',\n        options: {\n          name: '[name].[ext]', // Keeps the original file name\n          // Specify an absolute path where native modules should be outputted.\n          // For pkg or Electron, this might be a sub-directory.\n          rewritePath: path.resolve(__dirname, 'dist/native_modules'),\n          // When rewritePath is relative, use __dirname for resolution\n          useDirname: true \n        }\n      }\n    ]\n  },\n  // Important for Node applications to correctly resolve built-in modules\n  externals: [\n    {\n      // Prevent webpack from bundling Node.js built-in modules\n      // This is crucial for native addons that may depend on them.\n      'fs': 'commonjs fs',\n      'path': 'commonjs path',\n      'buffer': 'commonjs buffer',\n      'crypto': 'commonjs crypto'\n    }\n  ]\n};","lang":"javascript","description":"This webpack configuration demonstrates how to integrate `awesome-node-loader` to correctly process native `.node` files, specifying output paths and handling common external dependencies for Node.js environments."},"warnings":[{"fix":"Check the project's GitHub for compatibility updates or use a different loader (e.g., `node-loader` with appropriate configuration for newer webpack versions). Consider pinning webpack to v4 if this loader is critical.","message":"Explicit support for `webpack v4` suggests potential incompatibility with `webpack v5` or newer versions, leading to build failures or incorrect module resolution. Users on newer webpack versions should verify compatibility or consider alternative loaders.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Carefully review `rewritePath` and `useDirname` options. Ensure `rewritePath` is an absolute path to where the native module should reside at runtime, or `undefined` if webpack should handle its default embedding. Test thoroughly in the target environment.","message":"Misconfiguring `rewritePath` or `useDirname` options can lead to runtime errors like 'Module not found' or 'Module did not self-register' for native `.node` files, especially when bundling for different target environments (e.g., Electron, `pkg`). The `rewritePath` option should typically be `undefined` if embedding files directly into a self-contained package.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure that the `.node` files being bundled are pre-compiled for the specific target platform(s) and architecture(s) where the bundled application will run. For multi-platform support, you may need separate builds or dynamic loading of platform-specific binaries.","message":"Native `.node` modules are platform and architecture-specific. Using `awesome-node-loader` correctly bundles the specified `.node` files but does not automatically cross-compile or provide multiple binaries for different platforms (e.g., Windows, macOS, Linux, ARM, x64).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Run `npm install awesome-node-loader --save-dev` or `yarn add --dev awesome-node-loader` to install the loader in your project's dev dependencies.","cause":"Webpack cannot find the loader package because it's not installed or incorrectly referenced.","error":"Module not found: Error: Can't resolve 'awesome-node-loader' in '...' (webpack compile error)"},{"fix":"Verify the `rewritePath` and `useDirname` options in your `webpack.config.js`. Ensure the native module is copied to the correct runtime location and that Node.js can resolve its path. Use `path.resolve(__dirname, '...')` for absolute paths.","cause":"A native `.node` module is not found or incorrectly linked at runtime, often due to an incorrect output path or resolution.","error":"Error: The specified module could not be found. (Windows) or Error: Module did not self-register. (Linux/macOS) at process.dlopen (node:internal/modules/cjs/loader:XXXX)"},{"fix":"Check if your Webpack version is 4.x. If you're on Webpack 5 or newer, consider using an alternative loader that explicitly supports your Webpack version, or investigate if there are community-provided patches/forks for `awesome-node-loader`.","cause":"The loader might be incompatible with the current Webpack version (e.g., Webpack 5+), as it specifically mentions Webpack 4 support.","error":"ERROR in awesome-node-loader.js from awesome-node-loader / Webpack compilation failed: Cannot read property 'get' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null}