electron-vue 报错 ReferenceError: process is not defined

昨天的代码好好的没动,第二天早上一来项目就运行不起来了,报了这个ReferenceError: process is not defined,心想这也没改啥啊 谁还能动我代码不成?后来才知道那天更新了node版本12以上,之前是10.1.17,才导致的这个问题。所以直接把node退回到10版本的就行。https://nodejs.org/dist/latest-v10.x/ 这个地址是node之前发布过的版本。
当然,如果不想回退node版本的话就按照下面的步骤改下代码
首先修改.electron-vue下面的这两个文件

electron-vue 报错 ReferenceError: process is not defined_第1张图片
QQ图片20191128173310.png

首先修改renderer.config.js!
(图片为修改后的代码)直接复制下面代码替换就行了
electron-vue 报错 ReferenceError: process is not defined_第2张图片
QQ图片20191128173304.png

new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.resolve(__dirname, '../src/index.ejs'),
      minify: {
        collapseWhitespace: true,
        removeAttributeQuotes: true,
        removeComments: true
      },
      templateParameters(compilation, assets, options) {
        return {
          compilation: compilation,
          webpack: compilation.getStats().toJson(),
          webpackConfig: compilation.options,
          htmlWebpackPlugin: {
            files: assets,
            options: options
          },
          process,
        };
      },
      nodeModules: process.env.NODE_ENV !== 'production'
        ? path.resolve(__dirname, '../node_modules')
        : false
    }),

然后修改web.config.js的new new HtmlWebpackPlugin这一块 将下面代码复制替换

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-vue 报错 ReferenceError: process is not defined)