本文主要是对Electron使用过程中发下问题记录
问题一:electron安装容易没有办法安装
解决:用root权限执行安装,相关代码为:sudo npm -g install electron --unsafe-perm=true --allow-root
问题二:node install.js 安装缓慢
解决:打开终端,输入vi ~/.npmrc,在里面添加 electron_mirror="https://cdn.npm.taobao.org/dist/electron/";
问题三:出现代码段相关内容,主要是没有权限操作
(node:3607) UnhandledPromiseRejectionWarning: Error: EACCES: permission denied, mkdtemp '/usr/local/lib/node_modules/electron/electron-download-YboYGP'
(node:3607) 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:3607) [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.
解决:输入以下代码
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
问题四:electron+vue编译不成功,出现ERROR in Template execution failed: ReferenceError: process is not defined 对应字样
解决:对应下文件夹文件.electron-vue/webpack.web.config.js 和.electron-vue/webpack.renderer.config.js中的
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs’),
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: false
}),
改成
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: false
}),
问题五:在electron项目结构出现Uncaught TypeError: Cannot assign to read only property 'exports' of object,我的写法是 module.exports = {方法1,方法2},项目引用不管是require或import都报这个错误,此写法在其他的webpack框架是正常的。
解决:上述的方法导出改成 exports.方法1 代码为 exports.createKey=(key="")=>{}