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
8876 次点击
所在节点    程序员
35 条回复
kawowa
2019-11-06 08:20:01 +08:00
-g 安装时请开个管理员 cmd 或者 ps
binaryify
2019-11-06 09:06:35 +08:00
.npmrc
加一行
ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
dunhanson
2019-11-06 09:07:17 +08:00
@kawowa 我开了
dunhanson
2019-11-06 09:14:22 +08:00
@binaryify 加了毫无用处
不过奇怪的是我公司的笔记本正常,我没有安装 cnpm 和配置淘宝镜像,也没有开管理员权限执行 cmd
circleee
2019-11-06 09:16:04 +08:00
如果你是用 vue 的写 直接用 vue 的脚手架
orzorzorzorz
2019-11-06 09:25:06 +08:00
看上去是没权限。如果是因为是要安装在系统目录里导致的权限问题的话,可以先装个 nvm,这样 npm i -g 会装在非系统目录里,能绕开这个问题。
当然如果是因为有些文件因为墙没法下下来,那只能 npm 走代理了。
dunhanson
2019-11-06 09:27:11 +08:00
@circleee 不是 vue
dunhanson
2019-11-06 09:28:19 +08:00
@orzorzorzorz 我看提示的目录是用户临时目录下的,应该不存在没权限的问题,另外一台公司的笔记本啥都没配置,安装就正常的
dunhanson
2019-11-06 09:28:38 +08:00
@orzorzorzorz nvm 我研究下
cheeto
2019-11-06 09:45:24 +08:00
dunhanson
2019-11-06 09:57:47 +08:00
@cheeto 😂这个我搜到过,不行
wlf92
2019-11-06 09:59:55 +08:00
不要装 7.x.x 装 6.x.x,不要问为什么,问就是不知道。前几天才试的。
hantsy
2019-11-06 10:14:14 +08:00
尝试以下两步:

1. 用 Admin 运行 NPM 全局安装。
2. 这种估计必须用 代理,NPM 获取远程 electron 包。

我本地安装成功。
hantsy
2019-11-06 10:18:00 +08:00
C:\Windows\system32>npm -g install electron
C:\Users\hantsy\AppData\Roaming\npm\electron -> C:\Users\hantsy\AppData\Roaming\npm\node_modules\electron\cli.js

> core-js@3.3.6 postinstall C:\Users\hantsy\AppData\Roaming\npm\node_modules\electron\node_modules\core-js
> node postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> electron@7.1.0 postinstall C:\Users\hantsy\AppData\Roaming\npm\node_modules\electron
> node install.js

+ electron@7.1.0
added 86 packages from 90 contributors in 49.745s
hantsy
2019-11-06 10:18:41 +08:00
C:\Windows\system32>dir C:\Users\hantsy\AppData\Roaming\npm\node_modules\electron\dist
Volume in drive C is SYSTEM
Volume Serial Number is B0CF-8A64

Directory of C:\Users\hantsy\AppData\Roaming\npm\node_modules\electron\dist

11/06/2019 10:16 AM <DIR> .
11/06/2019 10:16 AM <DIR> ..
11/06/2019 10:16 AM 177,830 chrome_100_percent.pak
11/06/2019 10:16 AM 315,644 chrome_200_percent.pak
11/06/2019 10:16 AM 4,481,992 d3dcompiler_47.dll
11/06/2019 10:16 AM 104,578,048 electron.exe
11/06/2019 10:16 AM 2,128,896 ffmpeg.dll
11/06/2019 10:16 AM 10,426,784 icudtl.dat
11/06/2019 10:16 AM 141,824 libEGL.dll
11/06/2019 10:16 AM 7,731,200 libGLESv2.dll
11/06/2019 10:16 AM 1,060 LICENSE
11/06/2019 10:16 AM 4,723,060 LICENSES.chromium.html
11/06/2019 10:16 AM <DIR> locales
11/06/2019 10:16 AM 82,118 natives_blob.bin
11/06/2019 10:16 AM <DIR> resources
11/06/2019 10:16 AM 8,657,700 resources.pak
11/06/2019 10:16 AM 280,424 snapshot_blob.bin
11/06/2019 10:16 AM <DIR> swiftshader
11/06/2019 10:16 AM 701,096 v8_context_snapshot.bin
11/06/2019 10:16 AM 5 version
15 File(s) 144,427,681 bytes
5 Dir(s) 65,923,194,880 bytes free
joe237
2019-11-06 10:26:23 +08:00
看样子是权限问题。尝试一下,右键用管理员身份打开 cmd,再安装试试。或者你试试用 yarn 来安装看看

```
yarn global add electron

```
BoiledEgg
2019-11-06 11:43:50 +08:00
先降级到 6.1.4 安装吧,electron 7.1.0 build 时是下载到 ~\AppData\Local\Temp 文件夹的,似乎权限设置有问题
而之前都是下载到~\AppData\Local\electron\Cache 的
strahe
2019-11-06 12:16:04 +08:00
```
registry=http://registry.npm.taobao.org/
ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
electron_custom_dir=7.0.1
```

关键是 `electron_custom_dir` 手动写上安装的版本
dunhanson
2019-11-06 12:38:41 +08:00
@BoiledEgg @strahe
回头我试试
dunhanson
2019-11-06 12:39:29 +08:00
@hantsy 尝试过全局安装

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

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

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

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

© 2021 V2EX