02、 ReferenceError: process is n
2021-03-02 本文已影响0人
仙人掌开不了花
使用electron-vue搭建框架,运行yarn run dev
或 npm run dev
,桌面端应用报错
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
[EIALabel]/[html-webpack-plugin]/index.js:284:18
- runMicrotasks
- task_queues.js:97 processTicksAndRejections
internal/process/task_queues.js:97:5
解决方法:
- 找到根目录下的.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
},
# 增加templateParameters配置项 start
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
# 增加templateParameters配置项 end
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),
- 打开
webpack.web.config.js
文件,如下所示进行修改
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
# 增加templateParameters配置项 start
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
# 增加templateParameters配置项 end
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: false
}),
- 重新编译启动即可。