Error: Unexpected token } in JSON at position 3848

E:…>cordova platform add android
Running command: “C:\Program Files\nodejs\node.exe” E:…\hooks\before_platform_add\init_directories.js E:…
Using cordova-fetch for cordova-android@~6.2.2
Adding android project…
Creating Cordova project for the Android platform:
Path: platforms\android
Activity: MainActivity
Android target: android-25
Subproject Path: CordovaLib
Android project created with cordova-android@6.2.3
Error: Unexpected token } in JSON at position 3848

Run the same command with --verbose.

Also post your ionic info output please.

E:…\p…>ionic info
{ Error: Cannot find module 'E:…\node_modules\ionic’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at C:…\AppData\Roaming\npm\node_modules\ionic\bin\ionic:18:13 code: ‘MODULE_NOT_FOUND’ }

E:…>cordova run android
Running command: “C:\Program Files\nodejs\node.exe” E:\nainar\pt-app\hooks\after_prepare\010_add_platform_class.js E:…
add to body class: platform-android
Running command: “C:\Program Files\nodejs\node.exe” E:\nainar\pt-app\hooks\after_prepare\020_remove_sass_from_platforms.js E:…
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121
Reading build config file: E:…\app\build.json
Error: Cannot read property ‘length’ of undefined

C:…>ionic info
[WARN] You are not in an Ionic project directory. Project context may be missing.

cli packages: (C:…\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.9.2
ionic (Ionic CLI) : 3.9.2


Node : v6.11.2
npm  : 5.3.0
OS   : Windows 10

Hey, sooo I’m seeing a “length” error someone was recently asking about and the unexpected token “}”.

I’d advise you go anywhere you just edit (I don’t see the page you edited nor do you mention it), the length problem someone else solved cause:

example: any;

You have to define it like above (or well someone else had to); I think.

That should work. If not make sure you’re not missing or have an extra “}” in your code.


Actually @Arumuganainar 's environment looks a bit more broken. The not working ionic info and confused cordova run android points to deeper problems.

My suggestion:
Uninstall your node, install nvm (or nvm-windows when you are using Windows), install a new node with this, then install ionic and cordova again and try your command again. The problem should be gone.

1 Like

Yeah I thought it was something else too wasn’t too sure thought.


Hi @Sujan12  now i uninstall node, ionic, cordova and install again.
then create a new ionic-v1 project and run ionic cordova  run android still i get same issue  
Actually this app is ionic-v1 but current environment is latest version of node, ionic cordova

Still i confused how to fix this error 

E:\.....\myApp>ionic cordova run android
> ionic cordova prepare
> cordova prepare
√ Running command - done!
Running command: "C:\Program Files\nodejs\node.exe" E:\....\myApp\hooks\after_prepare\010_add_platform_class.js E:\sb-projects\myApp
add to body class: platform-android
> cordova run android
Running command: "C:\Program Files\nodejs\node.exe" E:\.....\myApp\hooks\after_prepare\010_add_platform_class.js E:\sb-projects\myApp

add to body class: platform-android
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121
Error: Cannot read property 'length' of undefined

[ERROR] An error occurred while running cordova run android (exit code 1).`Preformatted text`

Please edit your post, it is not very readable at the moment.
Use the </> button above the input field to format your code, command line output or error message (select the text first, then click the button or wrap it in ``` manually). Check the preview if it looks better. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.

The error message you posted now looks different to the one in your original post. Why do you say it is the same issue?

Now check it.i have formatted code
previous post is cordova project. Now i changed to ionic