V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dunhanson
V2EX  ›  程序员

npm 安装 electron 死活安不上

  •  
  •   dunhanson · 2019-11-06 00:05:59 +08:00 · 8839 次点击
    这是一个创建于 1605 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我用的管理员权限打开 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\[email protected]@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\_@[email protected]@@types\node
    [2/3] extract-zip@^1.0.3 installed at node_modules\[email protected]@extract-zip
    [3/3] @electron/get@^1.0.1 installed at node_modules\_@[email protected]@@electron\get
    execute post install 2 scripts...
    [1/2] scripts.postinstall @electron/[email protected][email protected] › core-js@^3.3.3 run "node postinstall || echo \"ignore\"", root: "C:\\Users\\dunhanson\\AppData\\Roaming\\npm\\node_modules\\electron\\node_modules\\[email protected]@core-js"
    [1/2] scripts.postinstall @electron/[email protected][email protected] › core-js@^3.3.3 finished in 70ms
    [2/2] scripts.postinstall [email protected] 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 [email protected] 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/[email protected][email protected] › @szmarczak/[email protected] › 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/[email protected][email protected] › boolean@^2.0.2(2.0.3) (17:42:58)
        → @electron/[email protected][email protected] › core-js@^3.3.3(3.3.6) (01:07:43)
      2019-10-31
        → @electron/[email protected][email protected] › 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)
    [[email protected]] 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
    
    35 条回复    2020-03-13 17:22:04 +08:00
    kawowa
        1
    kawowa  
       2019-11-06 08:20:01 +08:00 via Android
    -g 安装时请开个管理员 cmd 或者 ps
    binaryify
        2
    binaryify  
       2019-11-06 09:06:35 +08:00
    .npmrc
    加一行
    ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
    dunhanson
        3
    dunhanson  
    OP
       2019-11-06 09:07:17 +08:00
    @kawowa 我开了
    dunhanson
        4
    dunhanson  
    OP
       2019-11-06 09:14:22 +08:00
    @binaryify 加了毫无用处
    不过奇怪的是我公司的笔记本正常,我没有安装 cnpm 和配置淘宝镜像,也没有开管理员权限执行 cmd
    circleee
        5
    circleee  
       2019-11-06 09:16:04 +08:00
    如果你是用 vue 的写 直接用 vue 的脚手架
    orzorzorzorz
        6
    orzorzorzorz  
       2019-11-06 09:25:06 +08:00
    看上去是没权限。如果是因为是要安装在系统目录里导致的权限问题的话,可以先装个 nvm,这样 npm i -g 会装在非系统目录里,能绕开这个问题。
    当然如果是因为有些文件因为墙没法下下来,那只能 npm 走代理了。
    dunhanson
        7
    dunhanson  
    OP
       2019-11-06 09:27:11 +08:00
    @circleee 不是 vue
    dunhanson
        8
    dunhanson  
    OP
       2019-11-06 09:28:19 +08:00
    @orzorzorzorz 我看提示的目录是用户临时目录下的,应该不存在没权限的问题,另外一台公司的笔记本啥都没配置,安装就正常的
    dunhanson
        9
    dunhanson  
    OP
       2019-11-06 09:28:38 +08:00
    @orzorzorzorz nvm 我研究下
    cheeto
        10
    cheeto  
       2019-11-06 09:45:24 +08:00
    dunhanson
        11
    dunhanson  
    OP
       2019-11-06 09:57:47 +08:00
    @cheeto 😂这个我搜到过,不行
    wlf92
        12
    wlf92  
       2019-11-06 09:59:55 +08:00
    不要装 7.x.x 装 6.x.x,不要问为什么,问就是不知道。前几天才试的。
    hantsy
        13
    hantsy  
       2019-11-06 10:14:14 +08:00
    尝试以下两步:

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

    我本地安装成功。
    hantsy
        14
    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

    > [email protected] 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 -)


    > [email protected] postinstall C:\Users\hantsy\AppData\Roaming\npm\node_modules\electron
    > node install.js

    + [email protected]
    added 86 packages from 90 contributors in 49.745s
    hantsy
        15
    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
        16
    joe237  
       2019-11-06 10:26:23 +08:00
    看样子是权限问题。尝试一下,右键用管理员身份打开 cmd,再安装试试。或者你试试用 yarn 来安装看看

    ```
    yarn global add electron

    ```
    BoiledEgg
        17
    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
        18
    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
        19
    dunhanson  
    OP
       2019-11-06 12:38:41 +08:00
    @BoiledEgg @strahe
    回头我试试
    dunhanson
        20
    dunhanson  
    OP
       2019-11-06 12:39:29 +08:00
    @hantsy 尝试过全局安装
    dunhanson
        21
    dunhanson  
    OP
       2019-11-06 12:40:12 +08:00
    @joe237 我试试
    dunhanson
        22
    dunhanson  
    OP
       2019-11-06 12:46:48 +08:00
    @wlf92global 公司的笔记本正常,宿舍的电脑不行
    micookie
        23
    micookie  
       2019-11-06 12:55:36 +08:00 via Android
    一样的问题,我最后是手动解压安装的。
    TargaryenChen
        24
    TargaryenChen  
       2019-11-06 14:20:54 +08:00
    换个盘试试 别在 C 盘
    dunhanson
        25
    dunhanson  
    OP
       2019-11-06 19:57:02 +08:00
    @BoiledEgg 按你的方式安装低版本解决了
    但是搞不懂的是为啥我另外一台笔记本安装最新版本就没有问题
    dunhanson
        26
    dunhanson  
    OP
       2019-11-06 19:57:51 +08:00
    @joe237 用 yarn 也不行,我安装低版本解决了
    dunhanson
        27
    dunhanson  
    OP
       2019-11-06 19:58:18 +08:00
    @micookie 我试下手动安装看看
    dunhanson
        28
    dunhanson  
    OP
       2019-11-06 20:16:22 +08:00
    @micookie 离线包怎么安装?
    micookie
        29
    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
        30
    dunhanson  
    OP
       2019-11-07 10:02:52 +08:00
    @micookie
    😂不行,昨天晚上我就是这么做的,应该还有其它啥步骤
    joe237
        31
    joe237  
       2019-11-07 16:14:43 +08:00
    @dunhanson windows 平台实在是太特么的折磨了,不论是 7.x 还是 6.x 我这儿都装不上。同一时间开始搞的,在 mac 下的环境弄好了,demo 都 build 好了。。。
    micookie
        32
    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
        33
    micookie  
       2019-11-12 11:49:16 +08:00
    3、在 项目目录下 node_modules\electron 下创建 path.txt 文件,写入 electron.exe
    kidult
        34
    kidult  
       2019-12-26 20:01:31 +08:00
    使用 ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/" 设置后成功安装最新 7.1.7 版本
    kai2ex
        35
    kai2ex  
       2020-03-13 17:22:04 +08:00
    其实是 electron 下载器版本问题,devDependencies 里写死这个下载器版本就好了"@electron/get": "^1.0.1"
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1112 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:50 · PVG 06:50 · LAX 15:50 · JFK 18:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.