当我尝试在另一台计算机上运行打包的应用程序时,出现以下错误:
dlopen(/Users/holle/Downloads/Repeato.app/Contents/Resources/app/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node, 1): Library not loaded: /usr/local/opt/gstreamer/lib/libgstbase-1.0.0.dylib
Referenced from: /Users/holle/Downloads/Repeato.app/Contents/Resources/app/node_modules/opencv-build/opencv/build/lib/libopencv_videoio.3.4.dylib
Reason: image not found
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:740)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:166:20)
at Module.load (internal/modules/cjs/loader.js:620)
at tryModuleLoad (internal/modules/cjs/loader.js:559)
at Function.Module._load (internal/modules/cjs/loader.js:551)
at Module.require (internal/modules/cjs/loader.js:658)
at require (internal/modules/cjs/helpers.js:20)
at Object.<anonymous> (/Users/holle/Dow…opencv4nodejs.js:11)
at Object.<anonymous> (/Users/holle/Dow…opencv4nodejs.js:18)
此处记录了相同的问题,但是没有提供解决方案: https://github.com/electron-userland/electron-builder/issues/2738
我正在使用电子包装机进行构建,并使用命令npm run dist进行构建。 我在这里创建了该软件的精简版本: https://github.com/stoefln/opencv4nodejs-test
出于简化原因:这是package.json:
{
"name": "Rep",
"description": "...",
"version": "1.0.0",
"author": {
"name": "asdf",
"email": "asdf@gmail.com"
},
"repository": {
"type": "git",
"url": "...."
},
"build": {
"appId": "app....",
"productName": "Rep",
"mac": {
"category": "public.app-category.developer-tools"
},
"dmg": {
"contents": [
{
"x": 110,
"y": 150
},
{
"x": 240,
"y": 150,
"type": "link",
"path": "/Applications"
}
]
},
"nsis": {
"oneClick": "false",
"allowToChangeInstallationDirectory": "true"
},
"files": [
"!minicap/*",
"!minitouch/*"
],
"extraResources": [
"minicap/**",
"minitouch/**"
],
"directories": {}
},
"scripts": {
"electron-rebuild": "electron-rebuild -w opencv4nodejs",
"clean": "rm -rf node_modules",
"reinstall": "npm run clean && npm install",
"start": "concurrently \"npm run start-dev\" \"npm run start-electron\"",
"start-dev": "cross-env NODE_ENV=development webpack-dev-server",
"start-electron": "cross-env NODE_ENV=development electron index",
"build": "npm run dist && npm run build-all",
"bundle": "cross-env NODE_ENV=production webpack --config webpack.production.config.js",
"build-all": "build -lmw",
"test": "ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron ./node_modules/.bin/jest",
"prettier": "prettier --write app/**/*.js",
"prettier:staged": "pretty-quick --staged",
"postinstall": "electron-builder install-app-deps",
"pack": "npm run bundle && electron-builder --dir",
"dist": "npm run bundle && electron-packager . Repeato --ignore='app' --overwrite",
"setup:win": "./node_modules/.bin/build --prepackaged Repeato-win32-x64"
},
"keywords": [
"android",
"UI testing"
],
"license": "ISC",
"dependencies": {
"opencv4nodejs": "^4.11.0"
},
"devDependencies": {
"@devexpress/dx-react-core": "^1.10.5",
"@devexpress/dx-react-grid": "^1.10.5",
"@devexpress/dx-react-grid-material-ui": "^1.10.5",
"@material-ui/core": "^3.9.1",
"@material-ui/icons": "^3.0.2",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"classnames": "^2.2.6",
"concurrently": "^3.6.1",
"cross-env": "^5.2.0",
"css-loader": "^0.28.11",
"electron": "^3.1.1",
"electron-builder": "^20.28.4",
"electron-devtools-installer": "^2.2.4",
"electron-packager": "^13.1.1",
"electron-prebuilt-compile": "^3.0.10",
"electron-rebuild": "^1.8.2",
"fix-path": "^2.1.0",
"gulp": "^4.0.1",
"gulp-clean-dir": "^1.0.2",
"html-webpack-plugin": "^3.2.0",
"husky": "^1.3.1",
"jest": "^23.6.0",
"lodash": "^4.17.11",
"minimist": "^1.2.0",
"mobx": "^4.8.0",
"mobx-react": "^5.4.3",
"mobx-react-devtools": "^6.0.3",
"mobx-state-tree": "^3.10.0",
"node-loader": "^0.6.0",
"prettier": "^1.16.4",
"pretty-quick": "^1.10.0",
"react": "^16.5.1",
"react-dom": "^16.5.1",
"react-hot-loader": "^4.6.3",
"react-image-crop": "^6.0.18",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-sizeme": "^2.5.2",
"rxjs": "^6.3.3",
"style-loader": "^0.21.0",
"typeface-roboto": "0.0.54",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.14",
"webpack-node-externals": "^1.7.2",
"ws": "^6.1.2"
}
}
还有我的webpack.production.config.js
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
module.exports = {
entry: {
main: ['babel-polyfill', './app/index'],
worker: ['babel-polyfill', './app/worker.js']
},
mode: 'production',
output: {
filename: '[name]-bundle.js',
path: path.resolve(__dirname, 'static'),
publicPath: '/static/'
},
module: {
rules: [
{
test: /\.node$/,
use: 'node-loader'
},
{
test: /\.js$/,
exclude: /(node_modules|bower_compontents)/,
use: ['babel-loader']
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({ template: 'index.html', inject: false }),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
],
target: 'electron-renderer',
externals: [
nodeExternals({
whitelist: [/^(?!opencv4nodejs).*/i]
})
]
}