Electron-vue ReferenceError: process is not defined

在使用Electron-vue时,经过一顿安装,在最后执行"npm run dev"的时候,出现了如下的错误:

Electron-vue ReferenceError: process is not defined_第1张图片

Electron-vue ReferenceError: process is not defined

这个错误的的出现最初认为是缺少包,后来调研的时候发现网上大多是说nodejs的版本有问题,但是又不想把nodejs的版本进行降级处理。

后来在GitHub上发现了解决办法

需要在.electron-vue目录下修改webpack.web.config.jswebpack.renderer.config.js文件,并且两个文件中修改的东西是一样的

在原来的文件中是这样配置的

plugins: [
    new VueLoaderPlugin(),
    new MiniCssExtractPlugin({filename: 'styles.css'}),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.resolve(__dirname, '../src/index.ejs'),
      minify: {
        collapseWhitespace: true,
        removeAttributeQuotes: true,
        removeComments: true
      },
      nodeModules: false
    }),
    new webpack.DefinePlugin({
      'process.env.IS_WEB': 'true'
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin()
  ],

需要修改成

plugins: [
    new VueLoaderPlugin(),
    new MiniCssExtractPlugin({filename: 'styles.css'}),
    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: process.env.NODE_ENV !== 'production'
        ? path.resolve(__dirname, '../node_modules')
        : false
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin()
  ],

即在两个文件中都添加了下面这段代码

    templateParameters(compilation, assets, options) {
        return {
          compilation: compilation,
          webpack: compilation.getStats().toJson(),
          webpackConfig: compilation.options,
          htmlWebpackPlugin: {
            files: assets,
            options: options
          },
          process,
        };
      },

 

重新执行npm run dev

Electron-vue ReferenceError: process is not defined_第2张图片

你可能感兴趣的:(前端,Electron,electron-vue)