reactjs / webpack error can't resolve napi module

310 Views Asked by At

I made a simple c++ n-api module which works when started with node but fails to load in reactjs / webpack

const addon = require('./build/Release/module');

Module not found: Error: Can't resolve

The path to module is correct.

I'm using version: "react": "^16.8.6", "webpack": "^4.42.1", "node-addon-api": "^3.0.0"

Adding some info because the commenter didn't read it correctly which is probably my fault.

node-gyp compiles and create the binary "module.node"

Node reads this file when used in require function (within js) but reactjs doesn't understand it. example of the js file which works with nodejs:

const addon = require('./build/Release/winhandler');
var handle = addon.getWindowHandle();
console.log(`window handle ${handle}`);
addon.focusWindow(handle);
addon.minimizeWindow(handle);

so again, NodeJs reads it and functions can be called and work. ReactJs fails at "require"

what is needed (missing something in compile options or need different tools) to make this work with reactjs.

Hope someone can help me. Thank you.

0

There are 0 best solutions below