ionic-framework - @capacitor-community/electron 在构建的包上给出 Unhandled Promise Rejection
问题描述
当我使用@capacitor-community/electron
打包程序(使用电子生成器)打包 Ionic 项目时,出现以下错误:
Unhandled Promise Rejection
Error: ENOENT: no such file or directory, open 'D:/Users/.../example/electron/dist/win-unpacked/resources/app-update.yml'
重现问题的步骤:
# create generic ionic example
ionic start example tabs --type angular
cd example
npm i @capacitor-community/electron --save-dev
# required to add electron
ionic build
npx cap add @capacitor-community/electron
cd electron
# runs npm run build && electron-builder build --dir -c ./builder-effective-config.yaml
npm run electron:pack
这是主./example
项目的package.json:
{
"name": "example",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "~12.1.1",
"@angular/core": "~12.1.1",
"@angular/forms": "~12.1.1",
"@angular/platform-browser": "~12.1.1",
"@angular/platform-browser-dynamic": "~12.1.1",
"@angular/router": "~12.1.1",
"@capacitor-community/electron": "^4.0.3",
"@capacitor/app": "1.0.3",
"@capacitor/core": "3.2.4",
"@capacitor/haptics": "1.1.0",
"@capacitor/keyboard": "1.1.0",
"@capacitor/status-bar": "1.0.3",
"@ionic/angular": "^5.5.2",
"rxjs": "~6.6.0",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.1.1",
"@angular-eslint/builder": "~12.0.0",
"@angular-eslint/eslint-plugin": "~12.0.0",
"@angular-eslint/eslint-plugin-template": "~12.0.0",
"@angular-eslint/template-parser": "~12.0.0",
"@angular/cli": "~12.1.1",
"@angular/compiler": "~12.1.1",
"@angular/compiler-cli": "~12.1.1",
"@angular/language-service": "~12.0.1",
"@capacitor/cli": "3.2.4",
"@ionic/angular-toolkit": "^4.0.0",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"@typescript-eslint/eslint-plugin": "4.16.1",
"@typescript-eslint/parser": "4.16.1",
"eslint": "^7.6.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"jasmine-core": "~3.8.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.3.2",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"typescript": "~4.2.4"
},
"description": "An Ionic project"
}
这是package.json
项目./example/electron
:
{
"name": "example",
"version": "1.0.0",
"description": "An Amazing Capacitor App",
"author": {
"name": "",
"email": ""
},
"repository": {
"type": "git",
"url": ""
},
"license": "MIT",
"main": "build/src/index.js",
"scripts": {
"build": "tsc && electron-rebuild",
"electron:start-live": "node ./live-runner.js",
"electron:start": "npm run build && electron --inspect=5858 ./",
"electron:pack": "npm run build && electron-builder build --dir -c ./electron-builder.config.json",
"electron:make": "npm run build && electron-builder build -c ./electron-builder.config.json -p always"
},
"dependencies": {
"@capacitor-community/electron": "^4.0.1",
"chokidar": "~3.5.2",
"electron-is-dev": "~2.0.0",
"electron-serve": "~1.1.0",
"electron-unhandled": "~3.0.2",
"electron-updater": "~4.3.9",
"electron-window-state": "~5.0.3"
},
"devDependencies": {
"electron": "~13.1.9",
"electron-builder": "~22.11.7",
"electron-rebuild": "~2.3.5",
"typescript": "~4.3.5"
},
"keywords": [
"capacitor",
"electron"
]
}
这是electron-builder.config.json
文件:
{
"appId": "com.yourdoamnin.yourapp",
"directories": {
"buildResources": "resources"
},
"files": [
"assets/**/*",
"build/**/*",
"capacitor.config.*",
"app/**/*"
],
"publish": {
"provider": "github"
},
"nsis": {
"allowElevation": true,
"oneClick": false,
"allowToChangeInstallationDirectory": true
},
"win": {
"target": "nsis",
"icon": "assets/appIcon.ico"
},
"mac": {
"category": "your.app.category.type",
"target": "dmg"
}
}
解决方案
因此,显然问题在于默认发布方法。您需要将electron-builder.config.json
文件更改为以下形式(不带注释):
{
"appId": "com.yourdoamnin.yourapp",
"directories": {
"buildResources": "resources"
},
"files": [
"assets/**/*",
"build/**/*",
"capacitor.config.*",
"app/**/*"
],
"publish": {
"provider": "github",
"publishAutoUpdate": false // This is the line you need to add!
},
"extends":null,
"nsis": {},
"win": {
"target": "nsis",
"icon": "assets/appIcon.ico"
}
}
推荐阅读
- java - 如何在“mvn clean install”期间在 SpringBootTest 的运行中禁用 ch.qos.logback 自己的 INFO 消息
- linux - 如何获取当前终端窗口会话的PID、进程名、命令行?
- android - Android 自动镜像不适用于 Button Selector Drawable
- c# - .NET 5 中的 System.Text.Json 字段序列化未在 Swashbuckle API 定义中显示
- selenium - CI 代理操作系统在 webapp UI 测试中是否重要?
- powerbi - 没有交互的表格和切片器
- swift - 工作表内容不会根据参数更新
- javascript - 嗨,有人可以告诉我点击后如何关闭按钮吗?
- angular - Angular - 如何在另一个本地库中使用本地库
- swift - SwiftUI PageView 更新外部视图