question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v6] doesn't work with Webpack 5's DefinePlugin

See original GitHub issue

Preflight Checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Issue Details

  • Electron Forge Version:
    • 6.0.0-beta.54
  • Electron Version:
    • v11.3.0
  • Operating System:
    • Windows 10
  • Last Known Working Electron Forge version::
    • N/A

To Reproduce

I’m using electron-forge v6 with webpack v5.10.2. It looks like v6 doesn’t like webpack 5’s webpack.DefinePlugin.

My webpack.renderer.config.js looks like this:

module.exports = {
   ...,
   plugins: [
      new webpack.DefinePlugin({
         GLOBALS: JSON.stringify({
            BACKEND_URL: 'http://example.com'
         })
      }
   ]
}

I then use GLOBALS.BACKEND_URL in one of my .js files:

console.log(GLOBALS.BACKEND);

And then when I run yarn electron-forge start, I get this error:

ERROR in ./src/js/components/my_app-ajax.js
Module parse failed: parser.isAsiPosition is not a function
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
TypeError: parser.isAsiPosition is not a function
    at my_app\node_modules\webpack\lib\DefinePlugin.js:308:17
    at SyncBailHook.eval (eval at create (my_app\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:5:16)
    at SyncBailHook.lazyCompileHook (my_app\node_modules\tapable\lib\Hook.js:154:20)
    at Parser.walkIdentifier (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1986:25)
    at Parser.walkExpression (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1604:10)
    at Parser.walkMemberExpression (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1969:8)
    at Parser.walkExpression (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1610:10)
    at Parser.walkObjectExpression (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1678:9)
    at Parser.walkExpression (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1616:10)
    at Parser.walkExpressions (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1569:10)
    at Parser.walkCallExpression (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1949:35)
    at Parser.walkExpression (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1592:10)
    at Parser.walkVariableDeclaration (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1469:32)
    at Parser.walkStatement (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:997:10)
    at Parser.walkExportNamedDeclaration (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:1349:9)
    at Parser.walkStatement (my_app\node_modules\@electron-forge\plugin-webpack\node_modules\webpack\lib\Parser.js:961:10)

Additional Information

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
Bosch-Eli-Blackcommented, Mar 22, 2021

Ah, looks like there’s already a PR open for this: https://github.com/electron-userland/electron-forge/pull/2164

0reactions
Bosch-Eli-Blackcommented, Mar 14, 2022

@Deliaz We’re using it that way 🙂

var myConfig = {
   test: 'testing'
};

module.exports = {
   .....,
   plugins: [
	new DefinePlugin({
		GLOBALS: JSON.stringify(myConfig)
	}),
   ]
}

I vaguely seem to remember that maybe DefinePlugin only accepts stringified objects, but it looks like you’re passing strings to JSON.stringify(), which could be the problem 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

[v6] doesn't work with Webpack 5's DefinePlugin #2177 - GitHub
I'm using electron-forge v6 with webpack v5.10.2. It looks like v6 doesn't like webpack 5's webpack.DefinePlugin. My webpack.renderer.config.js ...
Read more >
DefinePlugin | webpack
The DefinePlugin replaces variables in your code with other values or expressions at compile time. This can be useful for allowing different behavior ......
Read more >
Webpack 5 and Storybook 6 integration throws an error in ...
Basically the error is coming from the marked line in /node_modules/webpack/lib/DefinePlugin.js once running for the first time npm run ...
Read more >
AngularJS with Webpack - Testing with Karma, Mocha, and Chai
Testing in Angular applications takes a bit of setup. Webpack simplifies things considerably. In this lesson you'll see how to test an Angular...
Read more >
Environment Variables : Webpack config using DefinePlugin
In simple terms, Environment Variables are variables that are set depending on the computer (server) the software is running on.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found