【问题标题】: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
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      • 2022-09-26
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      相关资源
      最近更新 更多