Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Need to copy and change names of .node files when dependency is built and ready to be used but in package.json as file: #35

@jhg

Description

@jhg
  • Operating System: Windows 10
  • Node Version: 15.3.0
  • NPM Version: 7.0.14
  • Yarn Version: 1.22.10
  • webpack Version: 4.46.0
  • node-loader Version: 1.0.2

Expected Behavior

Copy the index.*.node file to webpack_output directory and maybe it is good idea rename that from index (name in some native modules) to other to avoid collision

Actual Behavior

TypeError: Can not find node binding files from kobadonga-win32-x64-gnu, kobadonga-win32-x64-msvc and C:\Users\user\Documents\Repos\example-issue-node-loader\example\webpack_output\main\index.win32-x64-gnu.node, C:\Users\user\Documents\Repos\example-issue-node-loader\example\webpack_output\main\index.win32-x64-msvc.node
    at loadBinding (webpack-internal:///./node_modules/@node-rs/helper/lib/loader.js:27:11)
    at eval (webpack-internal:///./node_modules/kobadonga/index.js:3:18)
    at Object../node_modules/kobadonga/index.js (C:\Users\user\Documents\Repos\example-issue-node-loader\example\webpack_output\main\index.js:143:1)
    at __webpack_require__ (C:\Users\user\Documents\Repos\example-issue-node-loader\example\webpack_output\main\index.js:21:30)
    at eval (webpack-internal:///./src/main.ts:43:35)
    at Object../src/main.ts (C:\Users\user\Documents\Repos\example-issue-node-loader\example\webpack_output\main\index.js:155:1)
    at __webpack_require__ (C:\Users\user\Documents\Repos\example-issue-node-loader\example\webpack_output\main\index.js:21:30)
    at C:\Users\user\Documents\Repos\example-issue-node-loader\example\webpack_output\main\index.js:85:18
    at Object.<anonymous> (C:\Users\user\Documents\Repos\example-issue-node-loader\example\webpack_output\main\index.js:88:10)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)

Code

// webpack.config.js
const path = require('path');
const rules = require('./webpack.rules');
const plugins = require('./webpack.plugins').mainPlugins;

module.exports = {
  entry: './src/main.ts',
  target: 'electron-main',
  node: {
    __dirname: false,
  },
  module: {
    rules,
  },
  plugins,
  resolve: {
    alias: {
      '*': path.resolve(__dirname, 'node_modules'),
    },
    extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
  },
  devtool: 'cheap-module-eval-source-map',
  output: {
    path: path.resolve(__dirname, 'webpack_output/main'),
  },
};
// webpack.rules.js
module.exports = [
  // Add support for native node modules
  {
    test: /\.node$/,
    loader: 'node-loader',
  },
  {
    test: /\.(m?js|node)$/,
    parser: { amd: false },
    use: {
      loader: '@marshallofsound/webpack-asset-relocator-loader',
      options: {
        outputAssetBase: 'native_modules',
      },
    },
  },
  {
    test: /\.tsx?$/,
    exclude: /(node_modules|\.webpack)/,
    use: {
      loader: 'ts-loader',
      options: {
        transpileOnly: true,
      },
    },
  },
];

How Do We Reproduce?

Download the zip and the readme file has instructions to build and reproduce it:

example-issue-node-loader.zip

The native dependency is built first (using NAPI-rs) and it put the index.*.node in the package directory, in package.json files include *.node. The dependency is in the other package.json as a file: dependency, and can find the *.js file but do nothing about the native module file.

Additional information

I realize now about the .node file is not copied inside node_modules subdirectory even it is in package.json files property. Maybe because it is defined as file: dependency instead of a gzip.

Another try

Packing using yarn pack and using that in the file: path the .node file is in node_modules but the error is same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions