我用电子vue和电子生成器开发了我的应用程序,目标操作系统是Windows应用程序。
但是我发现,在dev模式下,它可以找到,但是当我构建它时,有些函数不能工作。
似乎与电子更新包相关的功能不起作用。
例如,使用dev模式运行,版本文本似乎与这段代码很好地兼容。但在生产模式下,该版本似乎不起作用。
但是,在dev模式中有一些错误,我不知道为什么要将app-update.yml文件放在node_modules文件夹中。它应该放在其他地方,因为node_modules文件夹被.ignore文件忽略了。如何处理app-update.yml目录路径?
┏ Electron -------------------
16:46:23.785 > Checking for update
┗ ----------------------------
┏ Electron -------------------
Window "main-window" was created
┗ ----------------------------
┏ Electron -------------------
16:46:23.915 > Error: Error: ENOENT: no such file or directory, open 'C:\myapp\node_modules\electron\dist\resources\app-update.yml'
┗ ----------------------------
┏ Electron -------------------
(node:20808) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'C:\myapp\node_modules\electron\dist\resources\app-update.yml'
┗ ----------------------------
┏ Electron -------------------
(node:20808) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:20808) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
┗ ----------------------------<template>
<Window title='Program Updater'>
<div class='wrap' id='currentAppVersion'>
Current App Version : {{currentAppVersion}}
</div>
<div class='wrap' id='checkNewVersion'>
Latest App Version : {{latestAppVersion}}
</div>
</Window>
</template>
<script>
import Window from '@/components/Window'
import Icon from '@/components/Icon'
export default {
name: 'update-window',
components: {
Window,
Icon
},
data () {
return {
// appVersion: app.getVersion()
currentAppVersion: process.env.npm_package_version,
latestAppVersion: 'Not yet Developed'
}
}
}
</script>发展模式

生产方式构建

这是我的package.json
package.json
{
...
"main": "./dist/electron/main.js",
"scripts": {
"build": "node .electron-vue/build.js && electron-builder",
"build:dir": "node .electron-vue/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"dev": "node .electron-vue/dev-runner.js",
"dev:tray": "node .electron-vue/dev-runner.js -- --systray",
"lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter src",
"lint:fix": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter --fix src",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"postinstall": "npm run lint:fix",
"publish": "build --win -p always",
"deploy": "electron-builder build --win --publish always"
},
"build": {
"productName": "Geomec Cloud Manager",
"appId": "com.apps.geomec-cloud-manager",
"artifactName": "Geomec-Cloud-Manager-Setup-v${version}.${ext}",
"nsis": {
"oneClick": true,
"installerIcon": "build/icons/setup-icon.ico",
"uninstallDisplayName": "Geomec Cloud Manager"
},
"directories": {
"output": "build"
},
"files": [
"dist/electron/**/*"
],
"win": {
"icon": "build/icons/app-icon.ico"
}
},
"dependencies": {
"electron-log": "^4.3.2",
"electron-updater": "^4.3.8",
"electron-window-manager": "github:evsar3/electron-window-manager",
"uuid": "^7.0.2",
"v-tooltip": "^2.0.3",
"vue": "^2.6.12",
"vue-electron": "^1.0.6",
"vue-js-toggle-button": "^1.3.3",
"vue-router": "^3.4.3",
"vue-switches": "^2.0.1",
"vuedraggable": "^2.24.1",
"vuex": "^3.0.1",
"vuex-electron": "^1.0.0"
},
"devDependencies": {
........
}发布于 2021-03-28 07:18:05
#4468认为,npm_package_version是由npm设定的,而不是由电子设置的。
你应该用app.getVersion()代替
返回String -加载应用程序的版本。如果应用程序的package.json文件中没有找到版本,则返回当前包或可执行文件的版本。
https://stackoverflow.com/questions/66812937
复制相似问题