zoukankan      html  css  js  c++  java
  • Mac下 nodejs 及 electron 安装

    nodejs文档: http://nodejs.cn/api/
    安装nodejs
    下载安装包 或者 mac 下   brew install nodejs
     
    安装electron
    nmp install -g electron
    如果报错    
    Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron/electron-tmp-download-1374-1511880539207'
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! electron@1.7.9 postinstall: `node install.js`
    npm ERR! Exit status 1
    npm ERR!
    这是 /usr/local/ 目录下的权限问题, 可以尝试 sudo chmod 777  /usr/local/, 如果还是不行  可以尝试关闭 csrutil
    解决方案:
    对于Mac OS X 10.11 El Capitan用户,由于系统启用了SIP(System Integrity Protection), 导致root用户也没有权限修改/usr/bin目录。按如下方式可恢复权限。
    屏蔽方法:重启Mac,按住command+R,进入recovery模式。选择打开Utilities下的终端,输入:csrutil disable并回车,然后正常重启Mac即可。
    具体可见:http://www.howtogeek.com/2304...
     
     在electron项目中
    报错:require is not defined

    修改创建BrowserWindow部分的相关代码,设置属性webPreferences.nodeIntegration为 true

    let win = new BrowserWindow({
        webPreferences: {
            nodeIntegration: true
        }
    })

     参考: https://www.cnblogs.com/kuku19940613/p/10814905.html

    嗯  主界面的这个错误解决了  然而  嵌套的iframe 里面又报这个错误。  这每个页面都要来这么一下么?

    这是找遍了各种  google 百度都没能解决我的问题  最典型的是以下的解决方案 这里也列出来 说不定能解决你们的问题呢?

    // 在主进程中
    const { BrowserWindow } = require('electron')
    let win = new BrowserWindow({
      webPreferences: {
        nodeIntegration: false
      }
    })
    win.show()

    假如你依然需要使用 Node.js 和 Electron 提供的 API,你需要在引入那些库之前将这些变量重命名,比如:<head>

    <script>
    window.nodeRequire = require;
    delete window.require;
    delete window.exports;
    delete window.module;
    </script>
    <script type="text/javascript" src="jquery.js"></script>
    </head>
    以上方法都用了 然鹅依然没有解决我的问题
    最终在这里找到了我的解决方案

    参考: https://stackoverflow.com/questions/45255773/electron-iframe-require-is-not-defined

    iframe.onload = function () {
      const iframeWin = iframe.contentWindow
      iframeWin.require = window.require
    })
    也就是在我的工程中
    在主进程中
    // 在主进程中
    const { BrowserWindow } = require('electron')
    let win = new BrowserWindow({
      webPreferences: {
        nodeIntegration: true
      }
    })
    win.show()

    在iframe嵌套的地方

    var node_frame = document.createElement("iframe");
    node_frame.onload = function () {
        node_frame.contentWindow.require = window.require
    };
  • 相关阅读:
    OpenJudge 2764 数根 C++
    OpenJudge / Poj 1835 宇航员 C++
    elasticsearch系统性能调优总结
    ES基本查询总结
    Vim最全快捷键键位图
    Idea常用插件整合
    微信小程序开发资源汇总
    Java JNI调用本地动态库使用详解
    java开发调试定位分析工具大全
    Redux-saga使用教程详解
  • 原文地址:https://www.cnblogs.com/lesten/p/11602083.html
Copyright © 2011-2022 走看看