久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在電子工作進(jìn)程中不能要求 node_modules

Cannot require node_modules in electron worker process(在電子工作進(jìn)程中不能要求 node_modules)
本文介紹了在電子工作進(jìn)程中不能要求 node_modules的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在嘗試在電子中使用網(wǎng)絡(luò)工作者.到目前為止,我能夠從渲染器進(jìn)程中實(shí)例化工作進(jìn)程,但是當(dāng)我嘗試在工作進(jìn)程中執(zhí)行 require('some_module') 時(shí),進(jìn)程會(huì)因錯(cuò)誤而崩潰.

I'm trying to use web workers in electron. So far I'm able to instanciate the worker process from the renderer process, but when I try to do a require('some_module') in the worker process the process crashes with the error.

找不到模塊some_module".

cjs 加載器顯然找不到我的模塊.但是,當(dāng)我從渲染器進(jìn)程進(jìn)行相同的 require 調(diào)用時(shí),我能夠 require 模塊.

The cjs loader cannot find my module apparently. But when I make the same require call from the renderer process, I'm able to require the module.

我已按照此處中提到的所有步驟進(jìn)行操作.此外,我還設(shè)置了選項(xiàng)nodeIntegrationInWorker: true,我可以毫無(wú)問(wèn)題地對(duì) fs 等節(jié)點(diǎn)內(nèi)置模塊進(jìn)行 require 調(diào)用.

I've followed all the steps mentioned here. Also I've set the optionnodeIntegrationInWorker: true and I can make require calls to node inbuilt modules like fs with no problems.

  1. __dirname 在渲染過(guò)程中解析為

  1. __dirname in the rendered process resolves to

root/node_modules/electron/dist/resources/electron.asar/renderer

并且在工作進(jìn)程中解析為

and in the worker process resolves to

root/node_modules/electron/dist/resources/electron.asar/worker

據(jù)我閱讀,require 函數(shù)應(yīng)該能夠在 node_modules 目錄中找到我的模塊,該目錄是 renderer 的父目錄>工人目錄

as far as I've done the reading the require function should be able to find my module in the node_modules dir which is parent to both the renderer and worker dir

快速查看 worker 中的 process 全局,發(fā)現(xiàn) process.type 等于 workerprocess.argv[1] 等于 --type=renderer 我覺(jué)得很奇怪.

A quick look at the process global in the worker reveals that process.type is equals worker while process.argv[1] is equals --type=renderer which I find strange.

<小時(shí)>

:電子版本=4.0.0",平臺(tái)=win32",拱=x64",節(jié)點(diǎn)版本=v10.11.0"


Meta: Electron version = "4.0.0", platform = "win32", arch = "x64", node version = "v10.11.0"

我們將不勝感激.

推薦答案

好的.作為一種解決方法,我使用它.

Ok. As a workaround, I use this.

    const paths = [
        path.join(process.resourcesPath, 'app.asar', 'node_modules'),
        path.join(process.resourcesPath, 'app', 'node_modules'),//when asar is disabled
        process.resourcesPath.replace(/electron[\/]dist[\/]resources/g, '')
    ];

    paths.map((path) => {
        global.require.main.paths.push(path);
    });

以上代碼片段手動(dòng)添加路徑節(jié)點(diǎn)查找以解析所需模塊.

The above snippet manually adds the paths node looks to resolve the required module.

這篇關(guān)于在電子工作進(jìn)程中不能要求 node_modules的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進(jìn)程中創(chuàng)建子窗口時(shí)如何修復(fù) BrowserWindow 不是構(gòu)造函數(shù)錯(cuò)誤) - IT屋-程序員軟件開(kāi)發(fā)技術(shù)
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應(yīng)用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無(wú)法在第二個(gè) loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內(nèi)使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲(chǔ)?)
How to access camera/webcamera inside electron app?(如何在電子應(yīng)用程序中訪問(wèn)相機(jī)/網(wǎng)絡(luò)攝像頭?)
主站蜘蛛池模板: 91精品国产综合久久久久久丝袜 | 久久成人一区 | 欧洲视频一区 | 91色视频在线观看 | 成人亚洲视频 | 日韩欧美亚洲综合 | 免费成人在线网站 | 亚洲综合一区二区三区 | 日韩av大片免费看 | 91久久精品国产91久久 | 九九九久久国产免费 | 91精品久久久久 | 一区二区在线 | 国产亚洲二区 | 日本高清中文字幕 | 秋霞精品| 91福利影院 | 毛片1| 一区二区三区精品在线视频 | 久久久久久国产一区二区三区 | 中文字幕在线国产 | 米奇狠狠鲁| 免费精品| 国产一区二区精品 | 天天干天天爱天天爽 | 国产精品久久久久久久免费大片 | 久久综合伊人 | 国产在线h | 精品久久影院 | 国产成人精品一区二三区在线观看 | 免费观看黄色一级片 | 国产成人精品综合 | 国产成人麻豆免费观看 | 999久久久免费精品国产 | 艹逼网 | 日韩精品视频在线免费观看 | 欧美日韩综合视频 | 亚洲精品中文在线 | 久久综合国产精品 | 欧美v片 | 毛片a |