Module Electron call node.js加载项抛出异常:”;错误:模块未自注册”;
我已经开发了一个node.js插件Demo.node-by-node-gyp。我的node.js版本是14.16.0,我使用的节点gyp也是14.16.0。当我在node中调用Demo.node时,它工作正常,但当我在electron中调用它时,它不工作 当我测试这个Demo.node时,我创建了一个Demo-test.js。在这个js文件中,我的代码如下:Module Electron call node.js加载项抛出异常:”;错误:模块未自注册”;,module,electron,Module,Electron,我已经开发了一个node.js插件Demo.node-by-node-gyp。我的node.js版本是14.16.0,我使用的节点gyp也是14.16.0。当我在node中调用Demo.node时,它工作正常,但当我在electron中调用它时,它不工作 当我测试这个Demo.node时,我创建了一个Demo-test.js。在这个js文件中,我的代码如下: const addonpath = 'C:/Windows/System32/Demo.node'; const addon = requ
const addonpath = 'C:/Windows/System32/Demo.node';
const addon = require(addonpath);
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
heigth: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.loadURL(`file://${__dirname}/page.html`);
mainWindow.on('closed', () => {
mainWindow = null;
});
const addonpath = 'C:/Windows/System32/Demo.node';
const addon = require(addonpath);
}
我使用follow命令来测试:
node demo-test.js
这样行
我的electron项目信息如下:
电子版:12.0.2
节点版本:14.16.0
铬:89.0.4389.90
我在main.js文件中使用插件,代码如下:
const addonpath = 'C:/Windows/System32/Demo.node';
const addon = require(addonpath);
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
heigth: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.loadURL(`file://${__dirname}/page.html`);
mainWindow.on('closed', () => {
mainWindow = null;
});
const addonpath = 'C:/Windows/System32/Demo.node';
const addon = require(addonpath);
}
当我调试时,electron在第行抛出异常
const addon=require(addonpath)
我的电子项目出了什么问题?同样的插件,为什么它可以在节点中工作,但不能在我的电子项目中工作