ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

Caught exception: SyntaxError: Unexpected end of JSON input

Open CraigHarley opened this issue 9 years ago • 4 comments

Short description of the problem:

I added some images into assets, then no ionic scripts work afterwards. I have tried rm -rf node_modules and reinstalled the dependencies. That didn't work, the error I'm getting is:

Craigs-MBP:ionic2app craigharley$ ionic info
Caught exception:
 SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.load (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/lib/config.js:13:24)
    at Object.<anonymous> (/usr/local/lib/node_modules/ionic/lib/utils/stats.js:31:31)
    at Module._compile (module.js:573:32)
    at Object.Module._extensions..js (module.js:582:10)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.require (module.js:500:17)
    at require (internal/module.js:20:19) 

What behavior are you expecting?

I should be able to run ionic scripts, I have tried ionic info,ionic serve

Steps to reproduce: Not sure how to reproduce this, the problem occured right after I created a folder in assets/img, however the images copied over to assets okay. Earlier today I installed android and ran ionic run android to my phone but I doubt that is related.

Output of ionic info below please

Craigs-MBP:ionic2app craigharley$ ionic info
Caught exception:
 SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.load (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/lib/config.js:13:24)
    at Object.<anonymous> (/usr/local/lib/node_modules/ionic/lib/utils/stats.js:31:31)
    at Module._compile (module.js:573:32)
    at Object.Module._extensions..js (module.js:582:10)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.require (module.js:500:17)
    at require (internal/module.js:20:19) 
Mind letting us know? https://github.com/driftyco/ionic-cli/issues

CraigHarley avatar Jan 27 '17 16:01 CraigHarley

The file that is read by:

    at Object.load (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/lib/config.js:13:24)

is ionic.config.json, which looks like:

{
  "name": "myapp",
  "app_id": "",
  "v2": true,
  "typescript": true,
  "gulpStartupTasks": [
    "sass",
    "watch"
  ],
  "watchPatterns": [
    "www/**/*",
    "!www/lib/**/*",
    "!www/**/*.map"
  ]
}

which looks correctly formed to me

CraigHarley avatar Jan 27 '17 17:01 CraigHarley

Commenting out the following function causes the app to build, I do get another error but it does build.

load: function() {
   // this.file = this.CONFIG_FILE;
   // if (fs.existsSync(path.join(home, this.file))) {
     // this.data = JSON.parse(fs.readFileSync(path.join(home, this.file)));
   // } else {
   //   this.data = {};
   // }
   // return this;
 },


watch failed: A watch configured to watch the following paths failed to start. It likely that a file 
            referenced does not exist: /Users/craigharley/code/myapp/ionic2app/src/assets/**/*, 
            /Users/craigharley/code/myapp/ionic2app/src/index.html, 
            /Users/craigharley/code/myapp/ionic2app/src/manifest.json, 
            /Users/craigharley/code/myapp/ionic2app/src/service-worker.js, 
            /Users/craigharley/code/myapp/ionic2app/node_modules/ionicons/dist/fonts/**/*, 
            /Users/craigharley/code/myapp/ionic2app/node_modules/ionic-angular/fonts/**/*, 
            /Users/craigharley/code/myapp/ionic2app/node_modules/ionic-angular/polyfills/polyfills.js, 
            /Users/craigharley/code/myapp/ionic2app/node_modules/sw-toolbox/sw-toolbox.js 

CraigHarley avatar Jan 27 '17 17:01 CraigHarley

Under your project root, check .io-config.json if should have something like: {"app_id":"xxxxxxxx"} if the file is empty, add {"app_id":"xxxxxxxx"} to it and replace the xxxxxx with the app id from ionic.config.json.

moatazsoli avatar Mar 29 '17 00:03 moatazsoli

Closed as this is the legacy CLI. If this is still an issue with the latest version, please make a new issue.

imhoffd avatar Jun 22 '18 15:06 imhoffd