Electron-vue報(bào)錯(cuò)Webpack ReferenceError:process is not defined

報(bào)錯(cuò) Webpack ReferenceError: process is not defined

最新重新安裝electron-vue后,使用yarn安裝項(xiàng)目,結(jié)果一直報(bào)錯(cuò)。起初以為是yarn的問(wèn)題,使用npm安裝也發(fā)現(xiàn)同樣的問(wèn)題。Google后發(fā)現(xiàn)應(yīng)該是node版本問(wèn)題,將node降為Node11可以正常工作。

ERROR in Template execution failed: ReferenceError: process is not defined
  
  ERROR in   ReferenceError: process is not defined
    
    - index.ejs:11 eval
      [.]/[html-webpack-plugin]/lib/loader.js!./src/index.ejs:11:2
    
    - index.ejs:16 module.exports
      [.]/[html-webpack-plugin]/lib/loader.js!./src/index.ejs:16:3
    
    - index.js:284 
      [electron-test]/[html-webpack-plugin]/index.js:284:18
    
    - runMicrotasks
    
    - task_queues.js:93 processTicksAndRejections
      internal/process/task_queues.js:93:5

解決方案

修改.electron-vue/webpack.web.config.js和.electron-vue/webpack.renderer.config.js文件的HtmlWebpackPlugin,添加templateParameters,修改后如下:

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
    }),
    

參考

https://github.com/SimulatedGREG/electron-vue/issues/871

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容