我read the docs,并且启用了节点集成:
win = new Electron.BrowserWindow({
show: false,
webPreferences: {
// allow code inside this window to use use native window.open()
nativeWindowOpen: true,
nodeIntegrationInWorker: true,
},
})
但是,它似乎不起作用。我在工作人员中遇到错误
Uncaught ReferenceError: require is not defined
在像
var _ = require("lodash")
我们如何使其工作?
最佳答案
在工作程序内部使用require
可以正常工作。
我在这里做了一个最小的示例:https://github.com/trusktr/electron-web-worker-example。
我的实际项目中肯定有问题(与该示例相比,这是很大的,并且正在执行一些自定义TypeScript转译)。
编辑,在我的情况下,问题是这样的(请参阅解决方案):https://github.com/electron/electron/issues/15609
关于javascript - 如何使节点集成在Electron Web Worker中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53167628/