简体   繁体   English

如何使节点集成在Electron Web Worker中工作?

[英]How to get node integration working in an Electron Web Worker?

I read the docs , and I have enabled node integration: 阅读了文档 ,并启用了节点集成:

win = new Electron.BrowserWindow({
    show: false,
    webPreferences: {
        // allow code inside this window to use use native window.open()
        nativeWindowOpen: true,
        nodeIntegrationInWorker: true,
    },
})

However, it doesn't seem to work. 但是,它似乎不起作用。 I get errors in the worker like 我在工作人员中遇到错误

Uncaught ReferenceError: require is not defined

on lines like 在像

var _ = require("lodash")

How do we make it work? 我们如何使其工作?

Using require inside a worker works. 在工人内部使用require可以工作。

I made a bare minimal example here: https://github.com/trusktr/electron-web-worker-example . 我在这里做了一个最小的示例: https : //github.com/trusktr/electron-web-worker-example

There must be something wrong in my actual project (which is huge compared to that example, and is doing some custom TypeScript transpilation). 我的实际项目中肯定有问题(与该示例相比,这是很大的,并且正在执行一些自定义TypeScript转译)。

EDIT, the problem in my case was this (see solution there): https://github.com/electron/electron/issues/15609 编辑,在我的情况下,问题是这样的(请参阅此处的解决方案): https : //github.com/electron/electron/issues/15609

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM