forge: JSON file "Failed to compile"

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Please describe your issue: I have some JSON files used for i18n in my app (using ng2-translate). In development using electron-forge start everything works great. After I run electron-forge make, the app throws an (impossible to diagnose) error Unexpected token F in JSON at position 0. Looking at DevTools’ Network tab, I see that the en.json file is found, but the response is the following error:

Failed to compile /Users/leifwells/Code/electron/ef-test/out/ef-test-darwin-x64/ef-test.app/Contents/Resources/app/src/www/assets/i18n/en.json: Cannot read property 'get' of null
TypeError: Cannot read property 'get' of null
    at /Users/leifwells/Code/electron/ef-test/out/ef-test-darwin-x64/ef-test.app/Contents/Resources/app/node_modules/electron-compile/lib/compiler-host.js:302:34
    at next (<anonymous>)
    at step (/Users/leifwells/Code/electron/ef-test/out/ef-test-darwin-x64/ef-test.app/Contents/Resources/app/node_modules/electron-compile/lib/compiler-host.js:47:191)
    at /Users/leifwells/Code/electron/ef-test/out/ef-test-darwin-x64/ef-test.app/Contents/Resources/app/node_modules/electron-compile/lib/compiler-host.js:47:361

Note of interest for future readers: The “F” in Unexpected token F in JSON at position 0 is the “F” in Failed to compile.

Obviously, something has gone wrong in the compile portion of the make process, but I am uncertain what it could be or how to avoid it. Surely other people have used JSON files have been used with Electron. 😉

Any guidance would be helpful.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I was attempting to load the CSV through D3, but it didn’t seem to matter what I used. If the file was part of the package then the compiler would mess with it.

I was able to get around the issue by renaming the file from a .csv to a .txt. The compiler ignores it now and eventually I plan on taking input from a database rather than a file anyway.

https://github.com/Lypzis/phaserAdvanced/blob/master/src/scripts/Preloader.js running on start works fine, the problem appears after package. line 18 is where it calls a .csv.

I’m having the same exact problem, but with a CSV file. Did anyone ever figure this out?

I experience the same issue with translation files for angular-translate. What confuses me most is that the file inside the resources folder exists and is not altered in any way, but accessing it through the WebView somehow involves the compiler cache and breaks it (giving me the same error as above).

I also can’t find a way to disable compilation of application/json files, if I add a passthrough option the compiler complains not having a compiler for application/json.

Versions:

electron-forge: 4.2.1 electron-compile: 6.4.2

Could someone suggest a work-around for this issue? I’ve run out of options.