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

Ionic upload gives Unexpected token < in JSON at position

Open mhartington opened this issue 9 years ago • 12 comments

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

mhartington avatar Dec 09 '16 20:12 mhartington

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..

mhartington avatar Dec 09 '16 20:12 mhartington

Same here. how to fix this?

svennela avatar Dec 10 '16 20:12 svennela

@dwieeb Any thoughts?

jthoms1 avatar Dec 12 '16 15:12 jthoms1

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

imhoffd avatar Dec 12 '16 15:12 imhoffd

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

uj avatar Jan 03 '17 04:01 uj

same issue

rama99 avatar Jan 08 '17 17:01 rama99

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

freddiescott avatar Jan 30 '17 10:01 freddiescott

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.

egalitarian11 avatar Feb 01 '17 18:02 egalitarian11

  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

koccaman avatar Feb 02 '17 10:02 koccaman

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..

saravanans-arch avatar Jan 04 '18 16:01 saravanans-arch

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

mukeshsmk avatar Jul 09 '18 06:07 mukeshsmk

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!

ionitron-bot[bot] avatar Jul 12 '18 16:07 ionitron-bot[bot]