![](/img/trans.png)
[英]Require.js Uncaught TypeError: undefined is not a function
[英]Cannot start JS application packed by Electron. Uncaught TypeError: require.nodeRequire is not a function
我通過Electron打包了我們的JS Web應用程序。
當我嘗試啟動此打包的應用程序時,出現以下錯誤:
text.js:未捕獲的TypeError:require.nodeRequire不是函數
在我們的RequireJS版本中沒有功能nodeRequire。
據我了解,RequireJSfor NodeJS的版本與RequireJSfor瀏覽器的版本不同。
我應該怎么做才能解決這個問題?
我應該在我們的網絡應用程序中使用其他版本的RequireJS嗎?
還是可以配置Electron來避免此錯誤?
Electron提供了適合我的配置。
// In the main process
var mainWindow = new BrowserWindow({
webPreferences: { nodeIntegration: false }
});
問題實際上不在Electron或RequireJS中,而是在text.js loader中 。 您實際上需要那個裝載機嗎?
它是require.js
如何尋找require.js
相對的; 電子如何加載網頁內容。 主要是masterconfig
環境,因此使用有問題的nodeRequire
。
跟進@Jose Rego的回答,該回答為我指明了正確的方向。
如果將nodeIntegration
設置為false
,則還需要確保將內容作為URL加載到瀏覽器中:
// Creazione della finestra del browser.
mainWindow = new BrowserWindow({ width: 800, height: 600,
webPreferences: { nodeIntegration: false } });
然后,當您加載內容時,將其指定為URL:
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, `[STATIC_CONTENT_PATH]`),
protocol: "file:",
slashes: true
})
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.