question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not load native module in production

See original GitHub issue
  • 19.56.2:
  • ia32:

Hi,

I want to use a custom native addon module in my electron app. The module is located in

C:\my-application-root-dir\node_modules\myaddon\build\Release\myaddon.node

and in src\main\index.js I require my module with relative path:

var myaddon = require('../../node_modules/myaddon/build/Release/myaddon')

in the package.json, I put my module in dependencies:

  "dependencies": {
    "myaddon":"^1.0.0",
  },

this config is working in the develop environment.

When I build my app with electron-builder for production, build was successfully and a setup file is generated, and I find the myaddon in unpacked directory under build

C:\my-application-root-dir\build\win-ia32-unpacked\resources\app.asar.unpacked\node_modules\myaddon\build\Release\myaddon.node

However after I install the application in another PC, A Javascript error occurred in the main process:

Cannot open C:\my-application-root-dir\node_modules\myaddon\build\Release\myaddon.node: Error: Uncaught Exception:
Error: Cannot find module .

After I search for answers for hours I found something in the document:

If you have native addons of your own that are part of the application (not as a dependency), set nodeGypRebuild to true.

does this mean, in my case, myaddon is not as a dependency? Should I put my myaddon inside /node_modules or in /src ?

And if I set nodeGypRebuild to true, the build process will fail, did I make something wrong?

Or the way I require my custom addon is wrong?

Any help would be appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

12reactions
lvbeckcommented, May 4, 2018

It seems that node-loader use a hardcore absolute path: https://github.com/webpack-contrib/node-loader/issues/12

issue solve by replace node-loader with native-ext-loader, I also test node-addon-loader, but it’s not working.

webpack.main.config.js:

      {
        test: /\.node$/,
        loader: 'native-ext-loader',        
        //use: 'node-addon-loader',
        //use: 'node-loader',
        options: {
          //rewritePath: path.resolve(__dirname, 'dist')
        },           
      }
0reactions
Vasanthvivicommented, Jul 5, 2021

i am also unable to load native dll using ffi

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to load some native node js modules with electron 4.0 ...
I got this to work. For native node js modules to work with electron 4 on Windows, it needs to be compiled with...
Read more >
Native Node Modules | Electron
When in doubt, run electron-rebuild first. Make sure the native module is compatible with the target platform and architecture for your Electron app....
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn...
Read more >
node-loader - webpack
Allows to connect native node modules with .node extension. ... electron-renderer / electron-preload value and do not mock the __dirname global variable.
Read more >
Using node modules with njs - Nginx.org
This can be solved by merging all the interdependent code into a single file. Tools like browserify or webpack accept an entire project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found