【问题标题】:Uncaught Error: Module name "electron" has not been loaded yet for context: _. Use require([])未捕获的错误:尚未为上下文加载模块名称“电子”:_。使用要求([])
【发布时间】:2021-06-04 21:34:23
【问题描述】:
我正面临这个错误:
未捕获的错误:尚未为上下文加载模块名称“电子”:_。使用 require([])
$scope.sendWhatsapp = function (report) {
let url = 'https://wa.me/91' + report.patient_phone_no + '?text=Hi, Your report is ready. Please visit the laboratory to collect it.'
console.log(typeof window.require);
if (typeof window.require === 'function') {
const shell = window.require('electron')
shell.openExternal(url);
}
}
提前致谢
【问题讨论】:
标签:
angularjs
electron
electron-builder
【解决方案1】:
只需设置一个全局变量并在 Angular 组件中访问它
**main.js**
app.whenReady().then(() => {`
let mainWindow = new BrowserWindow({`
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true
},
width:640,
height: 480,
resizable: false
})
... rest of code
**preload.js**
const { contextBridge, shell} = require('electron')
contextBridge.exposeInMainWorld(
'electron',
{
shell: shell
})