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.
@paulcbetts This looks familiar for some reason, I think it's the fallback compiler issue I tried to fix a while back
What's the contents of en.json?
{
"language": "en",
"appName": "blah",
"menu": {
"market": "Market",
"store": "Store",
"blah": {
"title": "Blah",
"icon": "md-stats"
},
"journalEntries": {
"title": "Journal Entries",
"icon": "md-search"
},
"changeStores": {
"title": "Change Stores",
"icon": "md-shuffle"
},
"appWalkthrough": {
"title": "App Walkthrough",
"icon": "md-help-circle"
},
"feedback": {
"title": "Feedback",
"icon": "md-chatbubbles"
},
"exit": {
"title": "Exit",
"icon": "md-log-out"
}
},
"pages": {
"account": {
"plan": "Plan",
"actual": "Actual",
"viewDetails": "View Graph",
"hideDetails": "Hide Graph"
},
"feedback": {
"title": "Feedback",
"category": "Category",
"generalFeedback": "General Feedback",
"bugReport": "Bug Report",
"featureRequest": "Feature Request",
"feedback": "Feedback",
"submit": "Submit",
"placeholder": "Share your thoughts...",
"placeholderOptional": "Share your thoughts (optional)..."
},
"journalSearch": {
"title": "Journal Entries",
"searchPlaceholder": "Search Accounts",
"instructions": "Search all accounts to find journal entries for the last closed month.",
"searchResults": "Search Results"
},
"blah": {
"title": "blah"
},
"walkthrough": {
"previous": "Previous",
"next": "Next",
"getStarted": "Let's Get Started"
}
},
"components": {
"accountFilterModal": {
"title": "Filter",
"viewBy": "View by",
"filter": {
"mtd": "Previous Month",
"mtd-short": "Previous Month",
"qtd": "Quarter to Date",
"qtd-short": "QTD",
"ytd": "Year to Date",
"ytd-short": "YTD"
},
"sort": {
"default": "Default (Paper)",
"overspend": "Overspend (High to Low)",
"plan": "Plan (High to Low)",
"actualSpend": "Actual Spend (High to Low)",
"name": "Account Name (Alphabetical)"
}
},
"accountList": {
"account": "Account",
"indexToPlan": "Index to Plan",
"toLastYear": "to LY",
"actual": "Actual",
"plan": "Plan"
},
"journalList": {
"noEntries": "There are no journal entries for this account.",
"showMore": "Show More",
"showLess": "Show Less",
"invoice": "Invoice",
"invoiceDate": "Invoice Date",
"document": "Document",
"department": "Department",
"departmentUnavailable": "Data Unavailable",
"glAccount": "G/L Account",
"vendor": "Vendor"
},
"kpi": {
"topLineMetrics": "Top Line Metrics",
"dollarSign": "$",
"percentSign": "%",
"sales": "Sales",
"controllableProfit": "Controllable Profit",
"indexToPlan": "Index to Plan",
"indexToLY": "Index to LY",
"toLastYear": "to LY",
"actual": "Actual",
"plan": "Plan"
},
"memoList": {
"title": "Memos",
"plan": "Plan",
"ofSales": "of Sales"
},
"segmentBar": {
"vsPlan": "VS PLAN",
"vsLY": "VS LY",
"vsPercentToSales": "% TO SALES"
}
},
"providers": {
"wmstore": {
"limitReached": "<span class=\"alert-red\">You have exceeded the single-day request limit and can not load store ::storenum:: or any more new stores. Your limit resets tomorrow.</span><br /><br /><span>Please enter another store number to change stores.</span>",
"storeUnavailable": "<span class=\"alert-red\">Data is unavailable for store ::storenum::.</span><br /><br /><span>Please enter another store number to change stores.</span>",
"promptLabel": "Please enter a store number to change stores."
}
}
}
Could someone suggest a work-around for this issue? I've run out of options.
Perhaps you could configure json to not be compiled? https://github.com/electron/electron-compile#how-can-i-compile-only-some-file-types-but-not-others
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
I'm having the same exact problem, but with a CSV file. Did anyone ever figure this out?
Problems with CSV file too, hoping for a solution.
Wait, you guys are trying to require a CSV file? Like require('./my.csv')??
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.
@Lypzis And you're getting a "failed to compile" error message?
Can you try using an absoluate path instead of a relative path, relative paths don't work too well in packaged apps because they are relative to the CWD which isn't really consistent in a packaged app.
path.resolve(__dirname, './assets/level1.csv')
I'm not getting any error at all, when I start the application ".exe" it only doesn't load that file.
Tried with absolute path and result was the same: 'yarn start' everything in the application works.
'yarn package' packs fine, open the ".exe", everything else is fine except for the .csv .
@Lypzis How is the CSV file being loaded, through an XHR request??
yes, according with the docs of the framework: https://phaser.io/docs/2.6.2/Phaser.Loader.html
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.
@Lypzis Can you try settings "text/csv" to "passthrough" in your .compilerc
like this?
{
"env": {
"development": {
"application/javascript": {
"presets": [
[
"env",
{
"targets": {
"electron": "1.8"
}
}
],
"react"
],
"plugins": [
"transform-async-to-generator"
],
"sourceMaps": "inline"
},
"text/csv":"passthrough"
},
"production": {
"application/javascript": {
"presets": [
[
"env",
{
"targets": {
"electron": "1.8"
}
}
],
"react"
],
"plugins": [
"transform-async-to-generator"
],
"sourceMaps": "none"
},
"text/csv":"passthrough"
}
}
}
Now it doesn't start:
App threw an error during load
Error: Found compiler settings for missing compiler: text/csv
Thanks @Tmktahu, it worked, though I don't think its the most practical solution having to change file extensions hehe.
As of version 6.0.0 electron-compile will not be used by default and this issue should stop happening, future issues should be raised on the electron-forge-plugin-compile repository in a post-6.0.0 world 馃憤