Skip to content

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

@695750180

Description

@695750180

我这边已经按照提示删除依赖重新安装 ,结果还是一直报这个错误
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)

Activity

codebytere

codebytere commented on Nov 7, 2019

@codebytere
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.

Legends

Legends commented on Nov 10, 2019

@Legends

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

695750180 commented on Nov 11, 2019

@695750180
Author

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

Legends

Legends commented on Nov 12, 2019

@Legends

@codebytere Do you need more information?

wtoalabi

wtoalabi commented on Nov 12, 2019

@wtoalabi

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

xland commented on Nov 20, 2019

@xland
Contributor

@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

BetaMee commented on Nov 24, 2019

@BetaMee

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

borsTiHD

borsTiHD commented on Nov 30, 2019

@borsTiHD

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

hgt803 commented on Dec 18, 2019

@hgt803

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

 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

HarwordLiu commented on Dec 20, 2019

@HarwordLiu

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

Kramy commented on Dec 20, 2019

@Kramy

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.

18 remaining items

bruceauyeung

bruceauyeung commented on Mar 6, 2020

@bruceauyeung
Contributor

@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

malept commented on Mar 6, 2020

@malept
Member

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

bruceauyeung

bruceauyeung commented on Mar 6, 2020

@bruceauyeung
Contributor

@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

malept commented on Mar 6, 2020

@malept
Member

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

xland commented on Mar 7, 2020

@xland
Contributor

@bruceauyeung

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

sincerefly

sincerefly commented on Mar 7, 2020

@sincerefly

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

xland commented on Mar 7, 2020

@xland
Contributor

@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

sincerefly commented on Mar 7, 2020

@sincerefly

@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

sincerefly commented on Mar 7, 2020

@sincerefly

@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

pangxieju commented on Mar 7, 2020

@pangxieju

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

xland commented on Mar 7, 2020

@xland
Contributor

@sincerefly

Thanks ,I'll try it later.

bruceauyeung

bruceauyeung commented on Mar 7, 2020

@bruceauyeung
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

bo-er commented on Mar 31, 2021

@bo-er

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

qhan1028 commented on Aug 28, 2021

@qhan1028

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @malept@Legends@jblevins1991@bruceauyeung@codebytere

        Issue actions

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