npm 安装 electron 死活安不上

2019-11-06 00:05:59 +08:00
 dunhanson

我用的管理员权限打开 cmd 的,但是一直提示 operation not permitted

D:\electron-quick-start>cnpm install electron@^7.1.0 -g
Downloading electron to C:\Users\dunhanson\AppData\Roaming\npm\node_modules\electron_tmp
Copying C:\Users\dunhanson\AppData\Roaming\npm\node_modules\electron_tmp\_electron@7.1.0@electron to C:\Users\dunhanson\AppData\Roaming\npm\node_modules\electron
Installing electron's dependencies to C:\Users\dunhanson\AppData\Roaming\npm\node_modules\electron/node_modules
[1/3] @types/node@^12.0.12 installed at node_modules\_@types_node@12.12.5@@types\node
[2/3] extract-zip@^1.0.3 installed at node_modules\_extract-zip@1.6.7@extract-zip
[3/3] @electron/get@^1.0.1 installed at node_modules\_@electron_get@1.6.0@@electron\get
execute post install 2 scripts...
[1/2] scripts.postinstall @electron/get@1.6.0 › global-agent@2.1.5 › core-js@^3.3.3 run "node postinstall || echo \"ignore\"", root: "C:\\Users\\dunhanson\\AppData\\Roaming\\npm\\node_modules\\electron\\node_modules\\_core-js@3.3.6@core-js"
[1/2] scripts.postinstall @electron/get@1.6.0 › global-agent@2.1.5 › core-js@^3.3.3 finished in 70ms
[2/2] scripts.postinstall electron@7.1.0 run "node install.js", root: "C:\\Users\\dunhanson\\AppData\\Roaming\\npm\\node_modules\\electron"
(node:1904) UnhandledPromiseRejectionWarning: Error: EPERM: operation not permitted, lstat 'C:\Users\DUNHAN~1\AppData\Local\Temp\electron-download-9qYJt2\electron-v7.1.0-win32-x64.zip'
(node:1904) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1904) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[2/2] scripts.postinstall electron@7.1.0 finished in 3s
Recently updated (since 2019-10-29): 5 packages (detail see file C:\Users\dunhanson\AppData\Roaming\npm\node_modules\electron\node_modules\.recently_updates.txt)
  2019-11-03
    → @electron/get@1.6.0 › got@9.6.0 › @szmarczak/http-timer@1.1.2 › defer-to-connect@^1.0.1(1.1.0) (00:04:18)
  2019-11-02
    → @types/node@^12.0.12(12.12.5) (01:49:46)
  2019-11-01
    → @electron/get@1.6.0 › global-agent@2.1.5 › boolean@^2.0.2(2.0.3) (17:42:58)
    → @electron/get@1.6.0 › global-agent@2.1.5 › core-js@^3.3.3(3.3.6) (01:07:43)
  2019-10-31
    → @electron/get@1.6.0 › global-agent@2.1.5 › roarr@^2.14.2(2.14.3) (09:04:17)
All packages installed (85 packages installed from npm registry, used 4s(network 1s), speed 980.54kB/s, json 81(180.96kB), tarball 1.06MB)
[electron@7.1.0] link C:\Users\dunhanson\AppData\Roaming\npm\electron@ -> C:\Users\dunhanson\AppData\Roaming\npm\node_modules\electron\cli.js

D:\electron-quick-start>npm -v
8893 次点击
所在节点    程序员
35 条回复
dunhanson
2019-11-06 12:40:12 +08:00
@joe237 我试试
dunhanson
2019-11-06 12:46:48 +08:00
@wlf92global 公司的笔记本正常,宿舍的电脑不行
micookie
2019-11-06 12:55:36 +08:00
一样的问题,我最后是手动解压安装的。
TargaryenChen
2019-11-06 14:20:54 +08:00
换个盘试试 别在 C 盘
dunhanson
2019-11-06 19:57:02 +08:00
@BoiledEgg 按你的方式安装低版本解决了
但是搞不懂的是为啥我另外一台笔记本安装最新版本就没有问题
dunhanson
2019-11-06 19:57:51 +08:00
@joe237 用 yarn 也不行,我安装低版本解决了
dunhanson
2019-11-06 19:58:18 +08:00
@micookie 我试下手动安装看看
dunhanson
2019-11-06 20:16:22 +08:00
@micookie 离线包怎么安装?
micookie
2019-11-07 09:24:48 +08:00
有点忘记了,我也是折腾了好久。
可以尝试下面 2 种方法
1、全局安装 electron,配置到环境变量

2、yarn 过程中,其实 electron 的包已经下载下来了,Windows 上在用户下的 AppData\Local\electron\Cache 中,把 zip 包手动解压到项目的 node_modules\electron\dist

我记得当时好像是这么处理的。
dunhanson
2019-11-07 10:02:52 +08:00
@micookie
😂不行,昨天晚上我就是这么做的,应该还有其它啥步骤
joe237
2019-11-07 16:14:43 +08:00
@dunhanson windows 平台实在是太特么的折磨了,不论是 7.x 还是 6.x 我这儿都装不上。同一时间开始搞的,在 mac 下的环境弄好了,demo 都 build 好了。。。
micookie
2019-11-12 10:12:06 +08:00
@dunhanson @joe237

1、手动下载最新版本 electron

https://npm.taobao.org/mirrors/electron/7.1.1/electron-v7.1.1-win32-x64.zip

2、解压 electron zip 包到:项目目录下 node_modules\electron\dist

3、在 项目目录下 node_modules\electron 下创建 path.txt 文件,内容是 项目目录 node_modules\electron\dist 的绝对路径

亲测有效。


过程是通过、node_modules\electron\install.js index.js 看出来的
micookie
2019-11-12 11:49:16 +08:00
3、在 项目目录下 node_modules\electron 下创建 path.txt 文件,写入 electron.exe
kidult
2019-12-26 20:01:31 +08:00
使用 ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/" 设置后成功安装最新 7.1.7 版本
kai2ex
2020-03-13 17:22:04 +08:00
其实是 electron 下载器版本问题,devDependencies 里写死这个下载器版本就好了"@electron/get": "^1.0.1"

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/616680

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX