Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token e in JSON at position 0 #40

Closed
mtarroyo opened this issue Jun 7, 2019 · 8 comments
Closed

SyntaxError: Unexpected token e in JSON at position 0 #40

mtarroyo opened this issue Jun 7, 2019 · 8 comments
Labels

Comments

@mtarroyo
Copy link

mtarroyo commented Jun 7, 2019

cordova 9.0.0 (cordova-lib@9.0.1)
ionic 5.0.1
native-run 0.2.3

When executing "ionic cordova run android" without specifying a target (Eg.: --device) the native-run script throws the following error:

SyntaxError: Unexpected token e in JSON at position 0

at JSON.parse (<anonymous>)
at Object.getNativeTargets (/usr/local/node/lib/node_modules/ionic/lib/native-run.js:103:44)

This is not so intuitive and take me some time to realise that the problema was the ausence of the "--device" option

@imhoffd
Copy link
Contributor

imhoffd commented Jun 7, 2019

@mtarroyo What is the output of native-run android --list --json --verbose ?

@mtarroyo
Copy link
Author

mtarroyo commented Jun 7, 2019

It outputs a bunch of information about SDK locations, android virtual devices and connected physical devices. Before finalize the execution it throws the following exception:

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, lstat '~/Android/Sdk/tools/����b'
Emitted 'error' event at:
    at fs.lstat (/usr/local/node/lib/node_modules/native-run/node_modules/@ionic/utils-fs/dist/index.js:252:22)
    at /usr/local/node/lib/node_modules/native-run/node_modules/graceful-fs/polyfills.js:282:31
    at FSReqWrap.oncomplete (fs.js:153:21)

@imhoffd imhoffd closed this as completed in ea2e0c5 Jun 7, 2019
@imhoffd
Copy link
Contributor

imhoffd commented Jun 7, 2019

@mtarroyo Okay, looks like a bug in the SDK walker. In the next release, native-run will simply log errors with directories or files instead of failing like that ^

@Ionitron
Copy link
Collaborator

Ionitron commented Jun 7, 2019

🎉 This issue has been resolved in version 0.2.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mtarroyo
Copy link
Author

mtarroyo commented Jun 7, 2019

cordova 9.0.0 (cordova-lib@9.0.1)
ionic 5.0.1
native-run 0.2.4

ionic cordova run android -l still gives me the following error if I do not specify --device option:

SyntaxError: Unexpected token e in JSON at position 0

at JSON.parse (<anonymous>)
at Object.getNativeTargets (/usr/local/node/lib/node_modules/ionic/lib/native-run.js:103:44)
at process._tickCallback (internal/process/next_tick.js:68:7)

And the command native-run android --list --json --verbose still gives me the same error as version 0.2.3:

native-run:android:utils:sdk:resolveSDKRoot Looking for $ANDROID_HOME +0ms
  native-run:android:utils:sdk:resolveSDKRoot Looking for $ANDROID_SDK_ROOT +3ms
  native-run:android:utils:sdk:resolveSDKRoot Using $ANDROID_SDK_ROOT at ~/Android/Sdk +3ms
  native-run:android:utils:sdk:resolveEmulatorHome Looking for $ANDROID_EMULATOR_HOME +0ms
  native-run:android:utils:sdk:resolveEmulatorHome Using $HOME/.android/ at ~/.android +1ms
  native-run:android:utils:sdk:resolveAVDHome Looking for $ANDROID_AVD_HOME +0ms
  native-run:android:utils:sdk:resolveAVDHome Using $HOME/.android/avd/ at ~/.android/avd +0ms
  native-run:android:utils:sdk:getSDKPackage Parsing ~/Android/Sdk/platform-tools/package.xml +0ms
  native-run:android:utils:avd:getAVDINIs Discovered AVD ini files: [ '~/.android/avd/Nexus_One_API_26.ini' ] +0ms
  native-run:android:utils:adb:getDevices Invoking adb: '~/Android/Sdk/platform-tools/adb' [ 'devices', '-l' ] +0ms
  native-run:android:utils:adb:parseAdbDevices Parsing adb devices from output lines: [ 'List of devices attached',
  native-run:android:utils:adb:parseAdbDevices   'XXXXXXXXXX             device usb:2-1.2 product:osprey_retla_ds model:XXXXXX device:osprey_uds transport_id:4',
  native-run:android:utils:adb:parseAdbDevices   '',
  native-run:android:utils:adb:parseAdbDevices   '' ] +0ms
  native-run:android:utils:adb:getDeviceProperties Invoking adb: '~/Android/Sdk/platform-tools/adb' [ '-s', '0023076282', 'shell', 'getprop' ] +0ms
  native-run:android:utils:sdk:findAllSDKPackages Walking ~/Android/Sdk to discover SDK packages +0ms
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, lstat '~/Android/Sdk/tools/����b'
Emitted 'error' event at:
    at fs.lstat (/usr/local/node/lib/node_modules/native-run/node_modules/@ionic/utils-fs/dist/index.js:252:22)
    at /usr/local/node/lib/node_modules/native-run/node_modules/graceful-fs/polyfills.js:282:31
    at FSReqWrap.oncomplete (fs.js:153:21)

@imhoffd imhoffd reopened this Jun 10, 2019
@imhoffd
Copy link
Contributor

imhoffd commented Jun 10, 2019

I must've missed something.

What is that weird file located at ~/Android/Sdk/tools/����b ?

@mtarroyo
Copy link
Author

mtarroyo commented Jun 11, 2019

Hi, @dwieeb!

I don't know how those files with strange encoded names has appeared on my Sdk/tools directory but they were the problem. By removing those files everything starts to work just fine!! By putting the files back then the error returns! Maybe at some point the native-run script is trying to evaluate the contents for the Sdk/tools directory and broke when cannot deal with a file that has a strange character encode on its name

@imhoffd
Copy link
Contributor

imhoffd commented Jun 11, 2019

I figured it was the issue, but I thought the tool was handling any sort of file errors gracefully. It should have just ignored the error and moved on... Glad to hear it's working for you now!

@imhoffd imhoffd closed this as completed Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants