当前位置: 首页 > 知识库问答 >
问题:

node.js - electron-vite初始化后用npm安装包失败?

宗增
2024-12-04

使用electron-vite初始化构建electron程序以后,想通过npm install来安装想用的包但发现什么包都装不进去报一样的错,报错具体如下,好像是路径有问题。希望有大佬能看看是需要怎么改也提前感谢能回复的大佬了。。。

npm error code 1
npm error path D:\paratice\elec-image
npm error command failed
npm error command C:\Windows\system32\cmd.exe /d /s /c electron-builder install-app-deps
npm error • electron-builder  version=24.13.3
npm error   • loaded configuration  file=D:\paratice\elec-image\electron-builder.yml
npm error   ⨯ open D:\paratice\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\node_modules\elec-image\package.json: The name of the file cannot be resolved by the system.
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).resolveDependency
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:197
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).processDependencies
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:100
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:61
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error github.com/develar/app-builder/pkg/node-modules.(*Collector).readDependencyTree
npm error       /Volumes/data/Documents/app-builder/pkg/node-modules/nodeModuleCollector.go:77
npm error   ⨯ D:\paratice\elec-image\node_modules\app-builder-bin\win\x64\app-builder.exe process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
npm error Exit code:
npm error 1  failedTask=installAppDeps stackTrace=Error: D:\paratice\elec-image\node_modules\app-builder-bin\win\x64\app-builder.exe process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
npm error Exit code:
npm error 1
npm error     at ChildProcess.<anonymous> (D:\paratice\elec-image\node_modules\builder-util\src\util.ts:252:14)
npm error     at Object.onceWrapper (node:events:633:26)
npm error     at ChildProcess.emit (node:events:518:28)
npm error     at ChildProcess.cp.emit (D:\paratice\elec-image\node_modules\cross-spawn\lib\enoent.js:34:29)
npm error     at maybeClose (node:internal/child_process:1104:16)
npm error     at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
npm error A complete log of this run can be found in: C:\Users\takuu\AppData\Local\npm-cache\_logs\2024-12-04T01_32_55_856Z-debug-0.log

刚开始是想安装quasar,发现装不上以为可能是包的问题,又装了axios试一下也一样报错。然后又根据chatgpt说的进行了下列操作

# 删除 node_modules
rm -rf node_modules

# 删除 package-lock.json 或 yarn.lock
rm package-lock.json
# 或
rm yarn.lock

# 清理 npm 缓存
npm cache clean --force

还是不行,啥的装不上,对于这个npm安装的原理是不太懂


追加补充根目录下的package.json的内容,npm i的操作也是在根目录下进行的

{
  "name": "elec-image",
  "version": "1.0.0",
  "description": "An Electron application with Vue",
  "main": "./out/main/index.js",
  "author": "example.com",
  "homepage": "https://electron-vite.org",
  "scripts": {
    "format": "prettier --write .",
    "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
    "start": "electron-vite preview",
    "dev": "electron-vite dev",
    "build": "electron-vite build",
    "postinstall": "electron-builder install-app-deps",
    "build:unpack": "npm run build && electron-builder --dir",
    "build:win": "npm run build && electron-builder --win",
    "build:mac": "npm run build && electron-builder --mac",
    "build:linux": "npm run build && electron-builder --linux"
  },
  "dependencies": {
    "@electron-toolkit/preload": "^3.0.1",
    "@electron-toolkit/utils": "^3.0.0",
    "elec-image": "file:",
    "quasar": "^2.17.4"
  },
  "devDependencies": {
    "@electron-toolkit/eslint-config": "^1.0.2",
    "@rushstack/eslint-patch": "^1.10.3",
    "@vitejs/plugin-vue": "^5.0.5",
    "@vue/eslint-config-prettier": "^9.0.0",
    "electron": "^31.0.2",
    "electron-builder": "^24.13.3",
    "electron-vite": "^2.3.0",
    "eslint": "^8.57.0",
    "eslint-plugin-vue": "^9.26.0",
    "prettier": "^3.3.2",
    "vite": "^5.3.1",
    "vue": "^3.4.30"
  }
}

共有2个答案

哈骞仕
2024-12-04

回答:报错中有一行 open D:\paratice\elec-image\node_modules………… The name of the file cannot be resolved by the system. 你的项目放在哪个文件夹下,难道你写了什么别的配置,让它解析依赖出现了循环,怎么这么多一样的名字的目录;可以把你的package.json文件内容贴一下

束福
2024-12-04

使用管理员权限 ,打开CMD 。
在运行npm install。 可以解决。

 类似资料:
  • 在安装 electtron 使总是失败,按照报错的信息提示,是证书已过期,感觉很奇怪,这里的证书是指什么证书呢。 环境信息:window10、node@18.19.0、npm@10.2.3。 该如何解决上面的问题呢?尝试多种网上的方式,均没有得到解决,使用的镜像是如下所示是国内镜像:

  • Git 配置 使用Git的第一件事就是设置你的名字和email,这些就是你在提交commit时的签名。 $ git config --global user.name "Scott Chacon" $ git config --global user.email "schacon@gmail.com" 执行了上面的命令后,会在你的主目录(home directory)建立一个叫 ~/.gitco

  • 由于Node.js平台是在后端运行JavaScript代码,所以,必须首先在本机安装Node环境。 安装Node.js 目前Node.js的最新版本是7.6.x。首先,从Node.js官网下载对应平台的安装程序,网速慢的童鞋请移步国内镜像。 在Windows上安装时务必选择全部组件,包括勾选Add to Path。 安装完成后,在Windows环境下,请打开命令提示符,然后输入node -v,如果

  • 论坛上的第一个帖子,希望有足够的细节让你帮我一把;-) 我正在尝试通过Node.js在我的Synology DS220上运行“TiddlyWiki”(一个笔记记录JavaScript应用程序),使用的官方教程如下:https://TiddlyWiki.com/static/installing%2520TiddlyWiki%2520on%2520node.js.html 而且还 到目前为止,我只得

  • 是否可以从zip文件安装npm更新?因为我可以通过firefox访问失败的github URL,并以这种方式下载它们。 我在代理后面运行,但已经将它添加到npm配置文件和apt.conf文件中,这样我就可以正确地apt-get或git克隆,有什么想法吗?im运行ubuntu服务器,14.04完全更新

  • 本文向大家介绍electron demo项目npm install安装失败的解决方法,包括了electron demo项目npm install安装失败的解决方法的使用技巧和注意事项,需要的朋友参考一下 electron官网提供的demo项目,在npm install 的时候总是报错显示安装失败, 解决办法:FQ即可成功安装。 以上这篇electron demo项目npm install安装失败的

  • node-v 16.20.2 npm-v 8.19.4 npm i 直接报错 用的 npm install --legacy-peer-deps 执行的

  • 我在我的android应用程序中使用谷歌地图。我已经创建了密钥并在清单文件中添加了必要的权限。但很快我启动了应用程序,我在调试器中收到了这条消息: Google服务初始化失败,状态:10,缺少用于初始化Google服务的预期资源:“R.string.google_app_id”。可能的原因是缺少google-services.json或com.google.gms.google服务gradle插件