Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nx-electron 11: No assets leads to webpack config error #82

Closed
patdx opened this issue Mar 12, 2021 · 1 comment · Fixed by #83
Closed

nx-electron 11: No assets leads to webpack config error #82

patdx opened this issue Mar 12, 2021 · 1 comment · Fixed by #83

Comments

@patdx
Copy link
Contributor

patdx commented Mar 12, 2021

Describe the bug

I upgraded an nx-electron app to v11 which was working fine before. It has a config like below:

        "build": {
          "builder": "nx-electron:build",
          "options": {
            "externalDependencies": [
              "electron"
            ],
            "main": "apps/desktop-app-main/src/main.ts",
            "outputPath": "dist/apps/desktop-app-main",
            "tsConfig": "apps/desktop-app-main/tsconfig.app.json",
            "webpackConfig": "tools/scripts/webpack/config-desktop-app-main.js"
          },

I guess there was previously an assets setting which I deleted since I was not using it.

Seems like even if it is gone, in the builder it is normalized to an empty array. Probably it gets normalized based on this schema.json?

So when I run nx build desktop-app-main, it checks if options.assets is truthy (it is), and tries to init the copy-webpack-plugin.

image

Since the array is empty, copy-webpack-plugin throws an error:

Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
 - options.patterns should be an non-empty array.

I can patch the nx-electron builder easily to get the desired result:

-    if (options.assets) {
+    if (options.assets && options.assets.length >= 1) {

Adding any kind of "stub" file/folder to the assets array fixes the issue too 😃

image

But I think ultimately, it would be nice to not throw an error if someone does the same thing as I did.

To Reproduce

  1. Clone this repo: https://github.com/patdx/nx-electron-test
  2. Run npm install and then npx nx build main

Note: I noticed when I tried to reproduce with a fresh workspace above that by default nx-electron inits an empty assets folder, so I guess this would only happen if someone tries to delete the assets config line (and forgets about it).

image

Expected behavior

I expect to be able to build the main app using nx build desktop-app-main even if no asset config is specified.

Screenshots

I attached some screenshots above.

Desktop (please complete the following information):

  • OS: Ubuntu via Windows WSL2
  • Nx Electron Version v11.0.0
patdx added a commit to patdx/nx-electron that referenced this issue Mar 12, 2021
@bennymeg
Copy link
Owner

Thank you for the detailed explanation and for fixing the issue!
I will merge it soon.

rajr5 pushed a commit to rajr5/nx-electron that referenced this issue Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants