alex8088 / electron-vite

Next generation Electron build tooling based on Vite 新一代 Electron 开发构建工具,支持源代码保护
https://electron-vite.org
MIT License
3.29k stars 141 forks source link

Can not run packaged macos dmg #224

Closed geohuz closed 1 year ago

geohuz commented 1 year ago

Describe the bug

The application window shows the following error:

Unexpected Application Error!
404 Not Found

The app runs without any problem in development mode, set export CSC_IDENTITY_AUTO_DISCOVERY=false to skip the code sign to build the dmg.

Electron-Vite Version

"electron-vite": "^1.0.25",

Electron Version

"electron": "^25.3.1", "electron-builder": "^23.6.0",

Vite Version

"vite": "^4.4.2"

Validations

geohuz commented 1 year ago

Running in preview mode I saw the following error:

Refused to load the font '<URL>' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.

Then I tried to fix the font src policy issue and now there is no error shows in the develop console. But the app window still has the same 404 error.

alex8088 commented 1 year ago

How to load your html file?

geohuz commented 1 year ago

I'm using the vitejs react scaffolder to develop then moved to vite-electron, create a project then copy the files from old project over render directory, I'm not sure if the index.html has any problem:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Tree Org</title>
    <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
    <meta
      http-equiv="Content-Security-Policy"
      content="default-src 'self'; img-src 'self' data:; font-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline'"
    />
  </head>

  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.jsx"></script>
  </body>
</html>

slightly changes in the content security rules for loading fonts and images.

alex8088 commented 1 year ago

https://electron-vite.org/guide/hmr.html#using-hmr

alex8088 commented 1 year ago

recommend https://electron-vite.org/guide/#scaffolding-your-first-electron-vite-project

geohuz commented 1 year ago

yeah I'm using yarn create @quick-start/electron to create the project, then moved my original vitejs source code into src/renderer, running nicely in development. here is the project structure:

Screenshot 2023-07-21 at 12 03 36

the hmr part in main/index.js is unchanged:

 // HMR for renderer base on electron-vite cli.
  // Load the remote URL for development or the local html file for production.
  if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
  } else {
    mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
  }
...
alex8088 commented 1 year ago

what is the preview mode?

geohuz commented 1 year ago

Sorry it is in the package.json:

"start": "electron-vite preview",

I suspect the issue is with react-router, still trying to figure out...

geohuz commented 1 year ago

My issue is with the react-router, change the router to hashrouter fix the issue.

Thanks!