Code Monkey home page Code Monkey logo

Comments (8)

marcoancona avatar marcoancona commented on June 2, 2024 1

For the records, 1.4.1 works for my setting. Thanks!

from electron-reload.

mscoobby avatar mscoobby commented on June 2, 2024

You can use something like path.join(__dirname, '..') to access files from the location of you entry point.

from electron-reload.

marcoancona avatar marcoancona commented on June 2, 2024

The problem is not on the user side, but on the library side, as it crashes executing the following line when the module is imported

const config = require(path.join(appPath, 'package.json'))

It requires a non-existing file based on the (not-necessarily true) assumption that package.json lies in the same folder of the program entry-point.

from electron-reload.

mscoobby avatar mscoobby commented on June 2, 2024

It may differ between the operation systems but getAppPath() should point to the location from where you are starting the app. If you are starting it with electron . (and not electron ./main/main.js) from the root of you project then it will find the package.json

from electron-reload.

yan-foto avatar yan-foto commented on June 2, 2024

I cannot reproduce the problem without knowing how your project is structured. Usually you define the entry point in the package.json and start the electron by pointing it to the directory including the package.json. Doing so would result in getAppPath() returning the directory in which the package.json is also located.

from electron-reload.

yan-foto avatar yan-foto commented on June 2, 2024

I think we can simplify the application logic by removing

const config = require(path.join(appPath, 'package.json'))
and replacing
const mainFile = path.join(appPath, config.main || 'index.js')
with

const mainFile = __filename

It should work as electron-reload is always initiated by the main file. @marcoancona could you give it a try and let me know? Thanks.

from electron-reload.

marcoancona avatar marcoancona commented on June 2, 2024

Yes, using const mainFile = __filename works for me. Alternatively, one could pass the path of mainFile optionally? This would handle all edge cases I guess.

For completeness, I should mention that the main in my package.json points to dist/main/main.js as in production the app is transpiled into a dist folder. This is the reason why, in development mode, I must run the app with electron main/main.js instead of electron .

from electron-reload.

yan-foto avatar yan-foto commented on June 2, 2024

So it turned out that __filename returns the location of electron-reload and not the parent file requireing it. So I was wrong. But I changed it to const mainFile = module.parent.filename and I suppose it should work now. I'll publish a new version and you can try it then.

from electron-reload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.