electron-vue的ReferenceError:process is not defined解决

本文介绍了如何修复在Windows环境下Electron-Vue项目中遇到的'process is not defined'错误,通过在Webpack配置文件中添加process变量。具体步骤是在.webpack.web.config.js和.webpack.renderer.config.js的 HtmlWebpackPlugin模板参数中增加process对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

electron-vue在Windows下面报process is not defined错误

使用electron-vue开发的时候报了如下错误

# 运行环境

  • node v12.16.3
  • npm 6.14.4
  • webpack v4.15.1
  • vue v2.5.16
  • vue-electron v1.0.6
  • electron v4.2.5
  • 系统 windows Server 2012 R2

# 解决方法

修改项目文件
.electron-vue目录下
- webpack.renderer.config.js
- webpack.web.config.js

在两个文件的new HtmlWebpackPlugin方法内(template及minify参数之间)追加代码,最终如下所示

// webpack.web.config.js
new HtmlWebpackPlugin({
    filename: 'index.html',
    template: path.resolve(__dirname, '../src/index.ejs'),
    // ----fix process is not defined----
    templateParameters(compilation, assets, options) {
        return {
            compilation: compilation,
            webpack: compilation.getStats().toJson(),
            webpackConfig: compilation.options,
            htmlWebpackPlugin: {
            files: assets,
            options: options
            },
            process,
        };
    },
    // ----fix process is not defined----
    minify: {
    collapseWhitespace: true,
    removeAttributeQuotes: true,
    removeComments: true
    },
    nodeModules: false
}),

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

# 测试

npm run dev就可以了

# 参考资料

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛定喵君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值