electron-userland / electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
1.01k stars 99 forks source link

Uncaught Error: ENOENT, config.json not found #197

Closed choxi closed 7 years ago

choxi commented 7 years ago

I have a config.json file in the root of my Electron app that doesn't seem to be found when I use electron-prebuilt-compile. I get the following error when I try to run electron .:

Uncaught Error: ENOENT, 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

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 tell electron-compile to include the config.json file? When I use the normal electron 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:

  1. Clone the repo, run npm install
  2. Run electron .

Thanks

MarshallOfSound commented 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 👍

choxi commented 7 years ago

@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
MarshallOfSound commented 7 years ago

How are you trying to read that file, can you share the line of code that attempts to locate it 👍

choxi commented 7 years ago

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

MarshallOfSound commented 7 years ago

@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")))
choxi commented 7 years ago

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 .

choxi commented 7 years ago

@MarshallOfSound your suggestion seems to be working for me, I haven't run into any unexpected issues using __dirname. Should I close this issue?

MarshallOfSound commented 7 years ago

Yep 👍