Closed choxi closed 7 years ago
@choxi Files in the root of your project aren't included by default in -compile
packaged projects. Move it into a folder and it will work 👍
@MarshallOfSound I tried moving the file from config.json
to config/config.json
and still get the same error:
Uncaught Error: ENOENT, config/config.json not found in /Users/Choxi/Code/electron-quick-start/node_modules/electron-prebuilt-compile/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar
How are you trying to read that file, can you share the line of code that attempts to locate it 👍
Sure thing, I have the full example uploaded at https://github.com/choxi/electron-quick-start and the specific line where I'm reading in the config file is here: https://github.com/choxi/electron-quick-start/blob/master/renderer.jsx#L6
@choxi Hm, normally you want to use __dirname
for relative paths.
Can you try this
const path = require('path');
let config = JSON.parse(fs.readFileSync(path.resolve(__dirname, "config/config.json")))
Awesome, that seems to fix it.
However, shouldn't app.getAppPath()
resolve to the same path whether
you're using electron
or electron-prebuilt-compile
? I originally moved
to using getAppPath
because I was having problems packaging my
application, I'm worried that using __dirname
will reintroduce those.
On Thu, Mar 02, 2017 at 10:22 PM, Samuel Attardnotifications@github.com wrote:
@choxi https://github.com/choxi Hm, normally you want to use __dirname for relative paths.
Can you try this
const path = require('path'); let config = JSON.parse(fs.readFileSync(path.resolve(__dirname, "config/config.json")))
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/electron/electron-compile/issues/197#issuecomment-283875980, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJCsN56Ez-KSNNPY6VjUJqDqCb7OcZhks5rh7G0gaJpZM4MR3Sz .
@MarshallOfSound your suggestion seems to be working for me, I haven't run into any unexpected issues using __dirname
. Should I close this issue?
Yep 👍
I have a
config.json
file in the root of my Electron app that doesn't seem to be found when I useelectron-prebuilt-compile
. I get the following error when I try to runelectron .
:If I comment out the
config.json
part of my code, it does seem to correctly compile my .jsx files so I know it's using the correct module. Is there something I need to do to tellelectron-compile
to include theconfig.json
file? When I use the normalelectron
module, it finds the file correctly so I was expecting it to do the same here.I've reproduced all of this in a fork of electron-quick-start: https://github.com/choxi/electron-quick-start. Steps to reproduce are:
npm install
electron .
Thanks