Ionic-cli: Ionic upload gives Unexpected token < in JSON at position

Created on 9 Dec 2016  路  12Comments  路  Source: ionic-team/ionic-cli

_From @kemalcany on December 8, 2016 9:49_

Ionic version: (check one with "x")
[ ] 1.x
[x ] 2.x

I'm submitting a ... (check one with "x")
[x ] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

ionic upload gives an Unexpected token < in JSON at position 2 (CLI v2.1.13) error

the source code i am trying to upload is just the tutorial template from ionic, nothing has been changed.

ionic info output: (Notice that the C letter in front of Cordova is missing from the output and it's not a copy paste error)

ordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.13
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.45
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v7.2.0
Xcode version: Not installed

_Copied from original issue: driftyco/ionic#9547_

old major version

Most helpful comment

  1. Login to https://apps.ionic.io/apps/
  2. Create a new app
  3. Copy created app ID
  4. Update ionic.config.json file in your project
  5. Build and upload again

All 12 comments

_From @kemalcany on December 8, 2016 9:59_

More information on this bug :

The output of the terminal when error happens is below:

An error occurred uploading the build: SyntaxError: Unexpected token < in JSON at position 2

SyntaxError: Unexpected token < in JSON at position 2
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (C:\Users\hello\AppData\Roaming\npm\node_modules\ionic\node_modules\ionic-app-lib\lib\upload.js:301:25)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

I did some digging and found out that the ionic-app-lib\upload.js expects a JSON at line 301 expects a JSON (code below) but receives an HTML instead, which looks like the compiled and final version of index.html.

      try {
 console.log(data);  // I've added this. The output is copied and pasted below:   
        jsonData = JSON.parse(data);
      } catch (parseEx) {

        // keep error msg reasonably short
        return q.reject(parseEx);
      }

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Ionic makes it incredibly easy to build beautiful and interactive mobile apps using HTML5 and AngularJS.">
    <meta name="keywords" content="html5,javascript,mobile,drifty,ionic,hybrid,phonegap,cordova,native,ios,android,angularjs">
    <meta name="author" content="Drifty">
    <meta property="og:image" content="http://ionicframework.com/img/ionic-logo-blog.png"/>

    <link rel="shortcut icon" href="https://ionic-apps.s3.amazonaws.com/img/favicon.png">

    <title>404 Not Found! - Ionic.io: the hybrid app platform.</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-resource.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-animate.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-cookies.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-animate.min.js"></script>
      <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.13/angular-ui-router.min.js"></script>
      <script type="text/javascript" src="//api.filepicker.io/v1/filepicker.js"></script>
      <script>
      filepicker.setKey("AabgSObTT8yIzUSh8zMNAz");
      </script>


    <link rel="stylesheet" href="https://ionic-apps.s3.amazonaws.com/CACHE/css/271f2c2db7ec.css" type="text/css" media="screen" />

.. Continues with the rest of HTML file..

Same here. how to fix this?

@dwieeb Any thoughts?

Might happen if the app is deleted. Let me see...

Same issue here. Any update to this? Is Ionic cloud not compatible with Ionic v2 uploads yet?

same issue

Same issue here with a new app that I created today.

I had this issue because I tried to build the package without uploading it first.

I've submitted a pull request that will handle the error before we get to the point of trying to parse HTML as JSON. Hope this helps.

  1. Login to https://apps.ionic.io/apps/
  2. Create a new app
  3. Copy created app ID
  4. Update ionic.config.json file in your project
  5. Build and upload again

Fixed! Same issue i was faced with cordova file transfer plugin,
But problem is
options.headers = {
"Content-Type":"application/json",
"Authorization" : your token
};
i used "Content-Type" : "application/json".. Once i removed that now its working perfectly..

I resolve this problem by removing platform (i.e. ionic platform rm android ). And add platform (i.e. ionic platform add android ) again.

Thanks for the issue! This issue appears to be associated with an old version of the Ionic CLI. Please update to the latest CLI version, which supports all versions of the Ionic Framework. If the issue is relevant and if it persists after updating to the latest CLI version, please create a new issue.

Thank you for using Ionic!

Was this page helpful?
0 / 5 - 0 ratings