Mac下 nodejs 及 electron 安装

mac2022-06-30  26

安装nodejs 参考:  https://nodejs.org/en/download/ 下载安装包   安装electron 参考:  https://electronjs.org/docs/tutorial/development-environment#setting-up-macos  nmp install -g electron 如果各种报错    /usr/local/ 目录下的权限问题  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! 解决方案: 对于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... 参考:  https://segmentfault.com/a/1190000018859442     报错: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()Copy

假如你依然需要使用 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 };

 

转载于:https://www.cnblogs.com/lesten/p/11602083.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)