Electron学习笔记 - 环境搭建

本篇文章主要介绍Electron开发环境的安装,主要包括:VSCode开发工具、NodeJS, Electron。本人所使用的环境为Mac Book Pro, Monterey 12.1版本。

1. 安装 VSCode

直接在官网下载安装


截屏2022-01-26 上午10.38.14.png

2. 安装 Nodejs

直接在官网下载安装


截屏2022-01-26 上午10.21.42.png

下载安装即可。验证安装成功,可输入以下命令。

node -v
v16.13.2

3. 安装Electron

变更源命令:

npm config set ELECTRON_MIRROR https://npm.taobao.org/mirrors/electron/

安装命令:

npm install -g electron

出现以下错误提醒

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/electron
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/electron'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/leying/.npm/_logs/2022-01-26T02_04_55_383Z-debug.log

采用下面的命令,解决权限问题。

sudo npm install -g electron --unsafe-perm=true --allow-root

检验安装是否成功的方法如下:

electron -v
v16.0.7
截屏2022-01-26 上午10.37.23.png

欢迎大家多提建议或意见。

最后更新:2022年1月31日

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容