Electron+vue开发遇到问题集锦,mac系统

本文主要是对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="")=>{}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值