Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron failed to install correctly, please delete node_modules/electron and try installing again #20994

Closed
695750180 opened this issue Nov 6, 2019 · 39 comments

Comments

@695750180
Copy link

我这边已经按照提示删除依赖重新安装 ,结果还是一直报这个错误
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
^

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
at getElectronPath (E:\学习资料\前端材料\设计模式\code\nodeJS脚本\npm-login\node_modules_electron@7.1.0@electron\index.js:14:11)
at Object. (E:\学习资料\前端材料\设计模式\code\nodeJS脚本\npm-login\node_modules_electron@7.1.0@electron\index.js:18:18)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object. (E:\学习资料\前端材料\设计模式\code\nodeJS脚本\npm-login\node_modules_electron@7.1.0@electron\cli.js:3:16)
at Module._compile (internal/modules/cjs/loader.js:936:30)

@codebytere
Copy link
Member

We require the template to be filled out on all new issues and pull requests. We do this so that we can be certain we have all the information we need to address your submission efficiently. This allows the maintainers to spend more time fixing bugs, implementing enhancements, and reviewing and merging pull requests. We will be able to more closely look at your issue once you do so.

@codebytere codebytere added the blocked/need-info ❌ Cannot proceed without more information label Nov 7, 2019
@Legends
Copy link

Legends commented Nov 10, 2019

Won't install electron, it hangs ♾️

Win10
Electron version: any version gets stuck
node -v
v12.13.0

image

The error message actually occurs when you cancel the hanging install and nevertheless try to run the project.

@695750180
Copy link
Author

Follow your approach ,It's the same problem @Legends but reduced version can be used. I use 6.x version。

@Legends
Copy link

Legends commented Nov 12, 2019

@codebytere Do you need more information?

@wtoalabi
Copy link

wtoalabi commented Nov 12, 2019

Same here.
Was working perfectly for me a week ago.
Could it be the new version?
I noticed that the 'dist' folder is not within the 'node_modules/electron' directory.

Would it be safe if I copy that folder from one of my old projects to the new one?

Thanks.

@xland
Copy link
Contributor

xland commented Nov 20, 2019

@695750180
@wtoalabi

  1. Create a file named path.txt in node_modules\electron folder.
  2. Write electron.exe in it.
  3. Download electron package manualy.
  4. Unpackage the electron files into node_modules\electron\dist
  5. Run your start script

@BetaMee
Copy link

BetaMee commented Nov 24, 2019

it is OK for Mac, create file path.txt, and add Electron.app/Contents/MacOS/Electron in that file.

@borsTiHD
Copy link

Same error here if I try to install electron v7.1.2.
I'm also behind a corporate/proxy firewall.
Idea from @xland is working. However, I installed electron on my private pc and then copied it (".\node_modules\electron") to the other pc. :)

@hgt803
Copy link

hgt803 commented Dec 18, 2019

我是这样重现该问题的,求解决

 nvm use 12
 cd ~/Desktop
 npm install @vue/cli -g
 vue create electron7-vue-demo
 cd electron7-vue-demo
 export ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
 vue add electron-builder
# 修改 package.json 的 "electron" 为 "^7.0.0"
 yarn
 yarn electron:serve

@HarwordLiu
Copy link

HarwordLiu commented Dec 20, 2019

I found a way in Chinese region.

Step 1. npm install electron
Step 2. download the electron zip from https://github.com/electron/electron/releases/download/v7.1.7/electron-v7.1.7-darwin-x64.zip
Step 3. copy the zip to /electron/dist
Step 4. vi ./node_modules/electron/path.txt and input /electron-v7.1.7-darwin-x64/Electron.app/Contents/MacOS/Electron

Finaly, you can run npm start.

But, it is not a good way to start electron.

@Kramy
Copy link

Kramy commented Dec 20, 2019

On Linux:

I was getting this error while installing electron because i had no acces to modify "/home/{user}/.cache/electron" directory.

Removing that directory and reinstalling electron worked to me.

@pangxieju
Copy link

Give it a try. 🤓
https://github.com/pangxieju/electron-fix

@ghost
Copy link

ghost commented Jan 7, 2020

Give it a try. 🤓
https://github.com/pangxieju/electron-fix

error fixed, but electron doesnt start

@mahhov
Copy link

mahhov commented Jan 9, 2020

I thought I had the same issue. npm i electron seems to hang. Aborting it and trying to run produces the error message 'Electron failed to install correctly, please delete node_modules/electron and try installing again'. Then I tried waiting longer for npm i electron finish. It took 10 whole minutes, but in the end, it installed and ran successfully.

@heavenkiller2018
Copy link

i have the same problem, what's happend? the new version was released without test fully?

@Hartha-aloufi
Copy link

I have the same problem also, i tried to delete node_modules many times and install electron with npm and yarn, also I tried different versions of electrons and get the same error !

@vigneshvenkat
Copy link

Navigating to installed "node_modules/electron" location and running "sudo node install.js" solved this issue for me. Electronv7.1.10 is running successfully now.

@sincerefly
Copy link

sincerefly commented Feb 8, 2020

Worked

Step 1. yarn
Step 2. download the electron zip from http://npm.taobao.org/mirrors/electron/8.0.0/electron-v8.0.0-win32-x64.zip
Step 3. unzip the zip to ./node_modules/electron/dist
Step 4. create ./node_modules/electron/path.txt file and input: electron.exe

Finaly, you can run yarn start.


解决方法

第一步,使用 yarn 安装依赖
第二步,下载安装包 http://npm.taobao.org/mirrors/electron/8.0.0/electron-v8.0.0-win32-x64.zip
第三步,解压缩安装包,将其内容放置到项目 ./node_modules/electron/dist(手动创建dist目录)
第三步,创建文件 ./node_modules/electron/path.txt 输入字符串 electron.exe 并保存

使用 yarn start 启动项目,报错消失

期待官方早日修复,印象中7.0版本就存在这个问题。


Update

  1. open cmd windows, set variable
    if with cmd
    set ELECTRON_MIRROR=https://cdn.npm.taobao.org/dist/electron/ (without quote)
    if with powershell
    $Env:ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"
    option, set DEBUG will display download detail (only npm display yarn not)
    set DEBUG=@electron/get:* (cmd) or $env:DEBUG="@electron/get:*" (powershell)
  2. install package
    yarn or npm i
  3. just launch app, It should be work.

  1. 设置淘宝镜像
    如果是cmd下
    执行 set ELECTRON_MIRROR=https://cdn.npm.taobao.org/dist/electron/ (URL没有引号)
    如果是powershell
    执行 $Env:ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"
    (可选)设置 DEBUG 环境变量可以输出下载详情(只针对npm有效)
    set DEBUG=@electron/get:* (cmd) 或者 $env:DEBUG="@electron/get:*" (powershell)
  2. 安装依赖
    yarnnpm i
  3. 启动运行
    Electron包下载成功,报错消失。

下载的缓存文件保存在了如下目录
C:\Users\用户名\AppData\Local\electron\Cache

@youngyou
Copy link

How about use this mirror?
ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"

@pangxieju
Copy link

Give it a try. 🤓
https://github.com/pangxieju/electron-fix

error fixed, but electron doesnt start

Give it a try. 🤓
$ npm install electron-fix -D
"scripts": {
"fix": "electron-fix start"
}

@pangxieju
Copy link

How about use this mirror?
ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"

Give it a try. 🤓
https://github.com/pangxieju/electron-fix
$ npm install electron-fix -D
"scripts": {
"fix": "electron-fix start"
}

@electron-triage electron-triage removed the blocked/need-info ❌ Cannot proceed without more information label Feb 26, 2020
@jblevins1991
Copy link

jblevins1991 commented Mar 4, 2020

Can we get a first party solution for this? It's really negligent to push untested and broken code that was discovered 4 months ago and it still be a problem. I could understand if it didn't effect devs in prod, but it does.

@malept
Copy link
Member

malept commented Mar 4, 2020

The docs have been updated to explain how to configure HTTP mirrors for Electron 7.0.0 and above: https://www.electronjs.org/docs/tutorial/installation#mirror

@malept malept closed this as completed Mar 4, 2020
@bruceauyeung
Copy link
Contributor

bruceauyeung commented Mar 6, 2020

@malept
I am using electron 7.1.13, windows 7 64bit, node v12.4.0 32bit, and using a Hong Kong proxy to install node modules. before running yarn install xxx ,

  1. just as the docs suggested, i configured electron mirror
    as the following:
ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
ELECTRON_CUSTOM_DIR="{{ version }}"

because i am using vue-cli-plugin-electron-builder, my postinstall scripts make sure any missing modules will be reinstalled
2. cleaned yarn cache via yarn cache clean
3, delete node_modules\electron
4, manually opened https://npm.taobao.org/mirrors/electron/7.1.13/electron-v7.1.13-win32-ia32.zip with my web browser (using my Hong Kong proxy) to make sure the link is reachable.

but unfortunately dist directory and path.txt file in node_modules\electron are still missing.

@malept
Copy link
Member

malept commented Mar 6, 2020

You can set the environment variable DEBUG=@electron/get:* to see what the downloader module is doing.

@bruceauyeung
Copy link
Contributor

bruceauyeung commented Mar 6, 2020

@malept
got didn't respect my proxy settings

image

D:\Home\icenter-next>yarn config list
yarn config v1.22.0
info yarn config
{
  'version-tag-prefix': 'v',
  'version-git-tag': true,
  'version-commit-hooks': true,
  'version-git-sign': false,
  'version-git-message': 'v%s',
  'init-version': '1.0.0',
  'init-license': 'MIT',
  'save-prefix': '^',
  'bin-links': true,
  'ignore-scripts': false,
  'ignore-optional': false,
  registry: 'https://registry.npmjs.org',
  'strict-ssl': false,
  'user-agent': 'yarn/1.22.0 ' +
    'npm/? ' +
    'node/v12.4.0 ' +
    'win32 ia32',
  lastUpdateCheck: 1583394514298,
  msvs_version: '2017'
}
info npm config
{
  'strict-ssl': false,
  'https-proxy': 'http://proxyhk.zte.com.cn:80/',
  'http-proxy': 'http://proxyhk.zte.com.cn:80/',
  ELECTRON_MIRROR: 'https://npm.taobao.org/mirrors/electron/',
  ELECTRON_CUSTOM_DIR: '{{ version }}'
}
Done in 0.32s.

@malept
Copy link
Member

malept commented Mar 6, 2020

The installation docs contains instructions on how to configure proxy support.

@bruceauyeung
Copy link
Contributor

bruceauyeung commented Mar 6, 2020

@malept sorry for the weird proxy problem. i rebooted my computer and the proxy problem is gone now and got can utilize proxy correctly.
i tried set DEBUG=@electron/get:* and set DEBUG=got:* for two independent yarn add xxx , electron is still broken and there are not any logs related to @electron/get and got module in the standard output console.

@malept
Copy link
Member

malept commented Mar 6, 2020

It's not clear that you're setting the DEBUG environment variable correctly. See the debug documentation for details.

Also, got does not use the debug module, so DEBUG=got:* won't do anything useful.

@xland
Copy link
Contributor

xland commented Mar 7, 2020

@bruceauyeung

try:
yarn config set ELECTRON_MIRROR http://npm.taobao.org/mirrors/electron/

@sincerefly
Copy link

I solved.

  1. open cmd windows, set variable
    if with cmd
    set ELECTRON_MIRROR=https://cdn.npm.taobao.org/dist/electron/ (without quote)
    if with powershell
    $Env:ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"
    option, set DEBUG will display download detail
    set DEBUG=@electron/get:* (cmd) or $env:DEBUG="@electron/get:*" (powershell)
  2. install package
    yarn or npm i
  3. just launch app, It should be work.

thanks @malept @bruceauyeung @youngyou

@xland
Copy link
Contributor

xland commented Mar 7, 2020

@sincerefly

Are you sure the address is correct?
https://cdn.npm.taobao.org/dist/electron/

This address response:

<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<RequestId>5E62F87C1897B339345537B9</RequestId>
<HostId>cdn.npm.taobao.org</HostId>
<Key>dist/electron/</Key>
</Error>

I think it should be https://npm.taobao.org/mirrors/electron

@sincerefly
Copy link

@xland

Yes, I test it.

Try: https://cdn.npm.taobao.org/dist/electron/v8.1.0/electron-v8.1.0-win32-ia32.zip

and npm install detail:

D:\code\electron-quick-start>npm i

> core-js@3.6.4 postinstall D:\code\electron-quick-start\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> electron@8.1.0 postinstall D:\code\electron-quick-start\node_modules\electron
> node install.js

  @electron/get:index Checking the cache (undefined) for electron-v8.1.0-win32-ia32.zip (https://cdn.npm.taobao.org/dist/electron/v8.1.0/electron-v8.1.0-win32-ia32.zip) +0ms
  @electron/get:index Cache miss +6ms
  @electron/get:index Downloading https://cdn.npm.taobao.org/dist/electron/v8.1.0/electron-v8.1.0-win32-ia32.zip to C:\Users\dong\AppData\Local\Temp\electron-download-qz5JpG\electron-v8.1.0-win32-ia32.zip with options: undefined +71ms
  @electron/get:index Checking the cache (undefined) for SHASUMS256.txt (https://cdn.npm.taobao.org/dist/electron/v8.1.0/SHASUMS256.txt) +10s
  @electron/get:index Cache miss +4ms
  @electron/get:index Downloading https://cdn.npm.taobao.org/dist/electron/v8.1.0/SHASUMS256.txt to C:\Users\dong\AppData\Local\Temp\electron-download-FFll6C\SHASUMS256.txt with options: undefined +3ms
  @electron/get:cache Moving C:\Users\dong\AppData\Local\Temp\electron-download-FFll6C\SHASUMS256.txt to C:\Users\dong\AppData\Local\electron\Cache\httpscdn.npm.taobao.orgdistelectronv8.1.0SHASUMS256.txt\SHASUMS256.txt +0ms
  @electron/get:cache Moving C:\Users\dong\AppData\Local\Temp\electron-download-qz5JpG\electron-v8.1.0-win32-ia32.zip to C:\Users\dong\AppData\Local\electron\Cache\httpscdn.npm.taobao.orgdistelectronv8.1.0electron-v8.1.0-win32-ia32.zip\electron-v8.1.0-win32-ia32.zip +609ms
npm notice created a lockfile as package-lock.json. You should commit this file.
added 86 packages from 96 contributors and audited 103 packages in 24.455s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

@sincerefly
Copy link

@xland

Suggest use https://cdn.npm.taobao.org/dist/electron/ with current electron version

With https://cdn.npm.taobao.org/dist/electron/ , you should setting ELECTRON_CUSTOM_DIR

eg:

# don't forget '/'
set ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/ 

#  change version if not use 8.1.0
set ELECTRON_CUSTOM_DIR=8.1.0

Beacuse the dist url dist is different

https://cdn.npm.taobao.org/dist/electron/v8.1.0/electron-v8.1.0-win32-ia32.zip
https://npm.taobao.org/mirrors/electron/8.1.0/electron-v8.1.0-win32-ia32.zip

Maybe the high version of electron's script modify the default dir.
with low version of electron, npm.taobao.org... maybe worked instead of cdn.npm.taobao.org...

@pangxieju
Copy link

Give it a try. 🤓 Open https://github.com/pangxieju/electron-fix

1、$ npm install electron-fix -D

2、Edit file ‘package.json’
"scripts": {
"fix": "electron-fix start"
}

3、npm run fix

@xland
Copy link
Contributor

xland commented Mar 7, 2020

@sincerefly

Thanks ,I'll try it later.

@bruceauyeung
Copy link
Contributor

It's not clear that you're setting the DEBUG environment variable correctly. See the debug documentation for details.

Also, got does not use the debug module, so DEBUG=got:* won't do anything useful.

@malept i set DEBUG as windows environment variable, set DEBUG=@electron/get:* is the command what i run before running yarn add xxx

@bo-er
Copy link

bo-er commented Mar 31, 2021

I found a way in Chinese region.

Step 1. npm install electron
Step 2. download the electron zip from https://github.com/electron/electron/releases/download/v7.1.7/electron-v7.1.7-darwin-x64.zip
Step 3. extract the zip and move the extracted folder to /electron/dist
Step 4. vi ./node_modules/electron/path.txt and input /electron-v7.1.7-darwin-x64/Electron.app/Contents/MacOS/Electron

Finaly, you can run npm start.

But, it is not a good way to start electron.

@qhan1028
Copy link

try add this env variable
ELECTRON_OVERRIDE_DIST_PATH=./node_modules/electron/dist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests