自学内容网 自学内容网

vue打包exe之electron-quick-start的npm install 报错

vue打包exe之electron-quick-start的npm install 报错

1、github地址

https://github.com/electron/electron-quick-start

2、问题

我使用的pnpm install正常安装,执行npm start提示错误
在这里插入图片描述

3、解决

package.json文件中加入

  "scripts": {
    "postinstall": "node node_modules/electron/install.js"
  },
  "config": {
    "electron": {
      "mirror": "https://registry.npmmirror.com/-/binary/electron/"
    }
  }

在这里插入图片描述
示例:

{
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
"start": "electron .",
    "postinstall": "node node_modules/electron/install.js"
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "^32.1.2"
  },
  "config": {
    "electron": {
      "mirror": "https://registry.npmmirror.com/-/binary/electron/"
    }
  }

}

4、其他(打包exe)

安裝打包插件:npm i electron-packager --save-dev

package.jsonscripts标签添加

"packager": "electron-packager ./ hello --out=release --platform=win32  --arch=x64 --overwrite --download.mirrorOptions.mirror=https://npm.taobao.org/mirrors/electron/  --ignore=node_modules"

参数解释:

命令解释如下:

  • ./ 表示项目目录是当前目录

  • hello 表示生成exe的名称

  • –platform=win32 表示运行时是windows

  • –out=release 表示生成目录是当前目录下的release 目录

  • –arch=x64 表示是64位平台

  • –overwrite 表示新生成的覆盖老的

  • –download… 表示依赖包采用国内的加速网络下载

  • –ignore 表示忽略node_modules的部分包版本,用来解决报错: This normally means that either you have deleted this package already somehow (check your
    ignore settings if using electron-packager). Or your module
    installation failed.

示例:

{
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "postinstall": "node node_modules/electron/install.js",
    "packager": "electron-packager ./ hello --out=release --platform=win32  --arch=x64 --overwrite --download.mirrorOptions.mirror=https://npm.taobao.org/mirrors/electron/  --ignore=node_modules"
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "^32.1.2",
    "electron-packager": "^17.1.2"
  },
  "config": {
    "electron": {
      "mirror": "https://registry.npmmirror.com/-/binary/electron/"
    }
  }
}

修改完配置,执行命令:

npm run packager

参考

https://juejin.cn/post/7084628134309396494
https://blog.csdn.net/dong_beijing/article/details/130461361
https://www.jb51.net/javascript/3178779pj.htm
https://www.jb51.net/javascript/3077301ir.htm


原文地址:https://blog.csdn.net/dzdzdzd12347/article/details/142451767

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!