zoukankan      html  css  js  c++  java
  • electron 中renderer.js中使用require('electron') 报错require is not defined

    在研究 渲染进程和主程序之前通信时,就在renderer.js 文件中写第一句代码

    const {ipcRenderer} = require('electron').ipcRenderer
     

    就报错,然后我就寻寻觅觅,寻寻觅觅呀,估算也找了小半天时间,然后,

    在我冷静下来仔细看看renderer.js 文件,在文件开头就有这样一句话

    // This file is required by the index.html file and will
    // be executed in the renderer process for that window.
    // No Node.js APIs are available in this process because
    // `nodeIntegration` is turned off. Use `preload.js` to
    // selectively enable features needed in the rendering
    // process.
    这句话很重要就是,理解起来就是,这个renderer.js 不可以使用node.js,如果要使用,你需要去,启动XXXXX
    看到这句话,百度起来就快了,网上给的答案在主进程中创建webPreference中修改他
    nodeIntegration:true(默认的是false)
     
    自问,我为啥呢么二,我也写了,然后再运行,报错依旧,我就很着急呀,why,
    划重点:我拼错了,,,如果你也入坑,请仔细仔细检查,你是不是也把这个写错了。正确的写法是
    webPreferences: {
          //注意大小写
          nodeIntegration:true,
          preload: path.join(__dirname, 'preload.js')  
        }
  • 相关阅读:
    excel数据 入库mysql 和 mysql数据 导入excel文件
    gson和fastjson将json对象转换成javaBean 简单对照
    docker入门
    jdbc 事务
    关于Java 实现抽象类的抽象方法的特性的利用---面向切面
    try}-with-resources
    关于虚拟机加载类的先后顺序测试
    MySQL api
    JS 截取字符串-全是干货
    JS截取字符串常用方法详细整理
  • 原文地址:https://www.cnblogs.com/fool-jingqiu/p/13362594.html
Copyright © 2011-2022 走看看