nklayman / vue-cli-plugin-electron-builder

Easily Build Your Vue.js App For Desktop With Electron
https://nklayman.github.io/vue-cli-plugin-electron-builder/
MIT License
4.12k stars 278 forks source link

WebpackOptionsValidationError configuration.target electron-preload #1873

Closed leongrdic closed 1 year ago

leongrdic commented 2 years ago

I'm getting the following error from webpack when i try to add preload: 'src/preload.js' to my vue.config.js:

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.target should be one of these:
   "web" | "webworker" | "node" | "async-node" | "node-webkit" | "electron-main" | "electron-renderer" | function
...

I'm using Webpack 4.28.4 which apparently doesn't support the electron-preload target that's currently hardcoded in this plugin: https://github.com/nklayman/vue-cli-plugin-electron-builder/blob/6a7b3ab3d9f4dd2aa666cbcdc53fc71689f3cccd/index.js#L683

When I manually change the line above to 'electron-renderer', everything works as expected.

What are my options, how can I avoid this error and preload the file?

MatthijsBurgh commented 2 years ago

The plugin is using webpack 4.46 right now. So try to update. Though I think it has worked with older webpack 4.x too.

leongrdic commented 2 years ago

How would you suggest I do that? I don't have webpack anywhere in my package.json.

I found that electron-preload has been introduced in Webpack v4.33.0 (https://github.com/webpack/webpack/releases/tag/v4.33.0)

Shouldn't this plugin's minimum webpack version be at least 4.33.0 then? (sorry if I got something wrong)

https://github.com/nklayman/vue-cli-plugin-electron-builder/blob/6a7b3ab3d9f4dd2aa666cbcdc53fc71689f3cccd/package.json#L48