Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upWebpack ReferenceError: process is not defined #871
Comments
|
Solved by removing: <% if (!process.browser) { %>
<script>
if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
</script>
<% } %>from Might not be the right solution but works as a temporary fix for me. Not sure issue should be closed though! |
|
I also ran into this issue. Is it possible that your Node version changed? I find that I can replicate this problem consistently by upgrading/downgrading Node, using NVM to switch between various versions. The fix, for me, was to |
|
Experiencing the same issue on Node 12.2.0. Not sure what causes it, and not entirely convinced the issue is in this repo. Probably a dependency. Removing parts from the template will work for My temporary solution was to do modify 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
}), |
|
I refactored my project to use this: https://github.com/nklayman/vue-cli-plugin-electron-builder. Works w/ Node 12, is generally simpler and more well documented. |
|
The same error appeared after updating nodejs to 12.2.0 (in 11 it was all working). The solution of wubzz solves it. |
I'm a new boy for javascript, how to do that, detail please |
|
@AIMentalModel have you first tried the solution from @LionelGarcia - about removing the section from the index.ejs file? I only mention because it has worked well for me. link to the comment -> #871 (comment) |
|
I also run into this issue after upgraded version of node to latest. I need v12 to use web workers. I don't think removing following:
is a real solution. I'm not sure how it will behavior when I'll switch from development to production. Any thoughts about that? I'm using windows 10. Edit @LionelGarcia you wrote that you have node v12.1.0 but do you mean your local node or you somehow updated node shipped with electron-vue? you can check local version by and local: |
|
@kmaher9 |
Cool well I'm glad you found a solution, consider closing this ticket off if your issue is resolved :) |
|
Seems to work for me using an older node version, node |
|
in mainWindow = new BrowserWindow({
height: 563,
useContentSize: true,
width: 1000,
title: 'TBFE',
webPreferences: {
nodeIntegration: true // add this
}
})And it will resolve this problem. |
|
add this code solved the problem for me templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
} |
where add this your code ? |
...electron-vue\webpack.renderer.config.js
|
|
i tried and only solution from @wubzz works |
|
I have the same issue... :( In my case the proposed workaround from @d0peCode worked for me. λ npm -v
6.10.3
λ yarn -v
1.15.2
λ node -v
v12.8.0 |
|
i had same issue, I solved by changing node version, i was using node v12.9.1 i changed to v10.16.2 and the issue was solved |
|
I edit webpack.renderer.config.js as below: new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
isBrowser: false,
isDevelopment: process.env.NODE_ENV !== 'production',
nodeModules: process.env.NODE_ENV !== 'production'
? path.resolve(__dirname, '../node_modules')
: false
}),and then change index.ejs like this: <!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
</script>
<% } %>
</head>
<body>
<div id="app">
</div>
<!-- Set `__static` path to static files in production -->
<% if (!htmlWebpackPlugin.options.isBrowser && !htmlWebpackPlugin.options.isDevelopment) { %>
<script>
window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
</script>
<% } %>
<!-- webpack builds are automatically injected -->
</body>
</html>
it just drops "process" and works perfectly for me. I hope this can help you. |
|
I have the same issue npm -v yarn -v node -v |
|
For this to have a PR that was merged to master and supposedly fixed the issue, I'm still getting the same error as well. |
|
I have the same issue. |
|
Pretty much in node v12+ you need to explicitly import the process module. Only change you need to make is below is update process to require('process'). I Can submit a PR if needed. No changes to your webpack config or anything is needed. <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vest</title>
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
</script>
<% } %>
</head>
<body>
<div id="app"></div>
<!-- Set `__static` path to static files in production -->
<% if (!require('process').browser) { %>
<script>
if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
</script>
<% } %>
<!-- webpack builds are automatically injected -->
</body>
</html> |
|
@ChrisKader 你的时非常正确的解决方案,希望大家采用他的解决方案。——node12.8的工作者的一句忠告。——i am from china |
Thank you! |
Either way, after being packaged as a web or app, the menu will not display correctly. But it can be displayed in the dev environment. |
it work well, thanks~ |
Cannot agree more, this works better, and the |
thank you, my node version is 12.14.1, this works for me. |
|
did anybody explain what is error mean? |
|
Is the temporary fix backwards compatible with Node v10.x ? Thanks |
|
This problem is really annoying, do we get an official fix in order to use latest version of Node? Would be nice, since this post is almost one year old, otherwise fuck this package and i'm going with other solutions... |
|
@blackw212 Electron + Parcel works 99% fine |
|
I can confirm @ChrisKader solution fix this error. |
|
When you need to re-configure half of the project to just run hello world, you know that you should not even go near that plugin.. I recommend using https://github.com/nklayman/vue-cli-plugin-electron-builder just imported to my premade project and BAM everything works! |
|
Any node version below 12 seems to work. So, version compability issue? |
|
Seems to also be general for Electron and not specifically this project. |
|
May as well let this thing die. It doesn’t seem like it’s going to be supported that much anymore. Use the vue cli and plugins and you can easily accomplish all the stuff this template does, and it works. |
|
as others have pointed out, @ChrisKader's solution works perfectly in |
solved my problem suscces! but ,What causes this problem? |
new questions is module.js:543 Uncaught Error: Cannot find module 'axios' , what happen |
very good :) |
|
Uncaught Error: Cannot find module 'axios' |





Issue
Fresh electron-vue project gives webpack error:
ReferenceError: process is not defined
Look like issue #516 solved by #726 for build:webReproduction
vue init simulatedgreg/electron-vue test_vue_error cd test_vue_error npm install npm run devScreenshot of rendering error
Development environment