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

在電子工作進程中不能要求 node_modules

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

問題描述

我正在嘗試在電子中使用網絡工作者.到目前為止,我能夠從渲染器進程中實例化工作進程,但是當我嘗試在工作進程中執行 require('some_module') 時,進程會因錯誤而崩潰.

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 加載器顯然找不到我的模塊.但是,當我從渲染器進程進行相同的 require 調用時,我能夠 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.

我已按照此處中提到的所有步驟進行操作.此外,我還設置了選項nodeIntegrationInWorker: true,我可以毫無問題地對 fs 等節點內置模塊進行 require 調用.

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 在渲染過程中解析為

  1. __dirname in the rendered process resolves to

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

并且在工作進程中解析為

and in the worker process resolves to

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

據我閱讀,require 函數應該能夠在 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 全局,發現 process.type 等于 workerprocess.argv[1] 等于 --type=renderer 我覺得很奇怪.

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.

<小時>

:電子版本=4.0.0",平臺=win32",拱=x64",節點版本=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);
    });

以上代碼片段手動添加路徑節點查找以解析所需模塊.

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

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

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

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 久久久精品视频免费看 | 成人在线不卡 | 啪一啪在线视频 | 韩国av一区二区 | 91av视频在线免费观看 | 日韩精品视频一区二区三区 | 精品一区在线 | 国产视频二区在线观看 | 国产精品视频在 | 国产一级特黄真人毛片 | 91中文在线观看 | 91精品在线播放 | 日产精品久久久一区二区福利 | 久久久久精 | 密乳av | 久久久久国产精品一区二区 | 亚洲国产成人精品女人久久久 | 国产精品久久久亚洲 | 正在播放亚洲 | 日本黄色一级片视频 | 成人精品在线视频 | 欧美偷偷操 | 有码一区 | 午夜播放器在线观看 | 97在线超碰| 欧美日韩高清在线观看 | 日本精品久久久久久久 | 国产日韩欧美在线 | 一区二区亚洲 | 国产精品成人一区二区三区 | 精国产品一区二区三区四季综 | 色本道| 国产福利视频在线观看 | 亚洲国产成人精品女人久久久 | 国产欧美日韩综合精品一 | 亚洲欧美日本在线 | 精品视频免费在线 | 日韩在线免费播放 | 欧洲视频一区二区 | 中文久久 | 日韩三片 |