bennymeg / nx-electron

Electron schematics for nrwl nx platform
Apache License 2.0
328 stars 85 forks source link

ERR_FILE_NOT_FOUND in packaged app #240

Closed dmatora closed 1 year ago

dmatora commented 1 year ago

packaged app is looking for assets from a wrong folder, getting GET file:///assets/index-e74d1eec.js net::ERR_FILE_NOT_FOUND

To Reproduce Steps to reproduce the behavior:

  1. npx create-nx-workspace@15
  2. npm install -D nx-electron 3.1 nx g @nrwl/react:app desktop-react 3.2. add missing libraries
  3. nx g nx-electron:app desktop-electron --frontendProject=desktop-react
  4. nx run desktop-react:build:production
  5. nx run desktop-electron:build:production
  6. nx run desktop-electron:package
  7. run dist/packages/mac/electron-react.app
  8. See ERR_FILE_NOT_FOUND in inspector

Expected behavior Expecting nx-electron to package working electron app

Desktop (please complete the following information):

image

bennymeg commented 1 year ago

Read the docs about setting the href.

dmatora commented 1 year ago

@bennymeg are you talking about setting it to './' ? I did that

dmatora commented 1 year ago

Ok, I've had a closer look and realized that you were talking about baseHref in workspace.json or in nx build my-app --baseHref="./" Initially I though you're talking about in apps/desktop-react/index.html Now I see these also add ./ prefix for assets, which is also necessary Added

      "configurations": {
        "development": {
          "mode": "development",
          "baseHref": "/"
        },
        "production": {
          "mode": "production",
          "baseHref": "./"
        }
      }
    },

to apps/desktop-react/project.json and things now work beautifully. Thanks for implementing that!

bennymeg commented 1 year ago

Out of interest, why did you used different "baseHref" setting? It should be the same.

dmatora commented 1 year ago

so that both production build and development serve are working (or else one of them don't)