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

add info about how to handle filepaths in electron #410

Open
Taschenbuch opened this issue May 6, 2023 · 1 comment
Open

add info about how to handle filepaths in electron #410

Taschenbuch opened this issue May 6, 2023 · 1 comment

Comments

@Taschenbuch
Copy link

From my own experience in my team at work and from the discord here that is one of the biggest issues for people setting up electron for the first time and even later it can cause confusion. Especially the part that it may work in development mode (electron .) but not after being packed and run via .exe, can be very confusing and can cost hours/days to fix when you are new to that.

should be covered:

  • relative paths are not working. Usage of __dirname to create absolute paths.
  • how to debug it: typically you see a white browserwindow and an error in devTools console. Use asar: false to check content of app(.asar) folder to check if everything is there you expected. if yes, a path could be an issue.
  • common pitfalls like when an ui framework is used it may need to be adjusted to work with absolute paths (?). example: create-react-app requires setting packagejson "homepage": ".". I think react requires usage of HashRouter instead of the normal router, too? Would be nice to have the fixes for common ui frameworks mentioned but maybe it is already enough to just give 1-2 examples for people to understand what it is about in general.
  • when a bundler like webpack is used, the paths may change. Then "main" in package.json needs to be updated and paths used for browserWindow.loadURL/file() need adjusting.
@Bricobit
Copy link

I'm trying electron for the first time and I'm going crazy with the paths, anything that is loaded even if you put a specific path, it puts the absolute path of the site where the file that does the loading is located in front of it, I want to keep my application agnostic because it uses libraries that import resources and that are dependencies of other projects that may or may not be running on a web server or in a local folder under electron, and because of the paths it breaks everything and I don't want to create two versions of my libraries, one for the web and another for electron because of the paths, it's a pain.

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

No branches or pull requests

2 participants