Unexpected Token Error in Particle CLI & DEV?

I have installed the Particle CLI & Particle Dev a month or so ago using the Windows Installer application and both programs successfully installed and worked.

Now I’m trying to use both of them, and I’m getting this error “Unexpected Token” from both applications.

I get this on the CLI:

I have ran npm update -g particle-cli & npm install -g particle-cli with the same results.

I upgraded Node js to the latest version and still get the same results.

Here is the error log I also get when trying to run Particle CLI:

I get the same Unexpected Token error when I try to run Particle Dev also.

And when I try click the check for update button in Atom it says it’s up to date.

@jvanier Any ideas as to what exactly needs to be fixed?

I feel like I should delete everything and install from scratch again but I’m not sure what all exactly the CLI Windows installer actually installed to get all this up and running :smile:

This looks like the user config stored in JSON format got corrupted somehow.

Try deleting the config in C:\Users\your_user.particle\profile.json and C:\Users\your_user.particle\particle.config.json then doing particle login again.

@jvanier I can not find those files on my PC anywhere which may be the reason for the error.

I deleted everything I could find relating the Particle CLI, Node.js, Python, Git, etc… And then I tried to install the Particle CLI again and see this error in the installer log.

Any ideas why this is happening on install?

Here is the error log data:

@jvanier @kennethlimcp OK, after looking at the laptop that has the working CLI I found the .particle folder that contains the Config.json & Profile.json files in them.

The laptop that I am having issues with was missing this folder because I probably deleted it while troubleshooting the Google Cloud tutorial Rickkas posted up a few week ago that was also giving me token errors.

I get token errors for the CLI, DEV, and the Google Cloud Datastore app.

So I copied the .Particle folder over to the laptop I’m having these Token errors on hoping it would fix the issues but I get the same Unexpected token error.

Even if I delete the Config.json & Profile.json files and then run the particle login command the same error pops up.

Even though I deleted the .particle folder in the past, uninstalling and reinstalling the Particle CLI never did create a new .particle folder for some reason. Should it create the .Particle folder every time the Window CLI installer is ran?

Any solutions to this other than wiping the whole laptop clean which would be less than ideal?

Thanks for your help :smile:

Can you post the file C:\Users\RWB\AppData\Local\particle\node_modules\particle-cli\settings.js? I’ll add some console.log statements in there to print more debug info, send it back to you so we can figure out what’s going on.

@jvanier Here is the link to the settings.js file you requested:

Thanks for your help :wink:

OK, replace the settings.js file with this one:

When you run the CLI you should see additional logs which should point to which file is corrupted.

OK, I replaced the settings.js file with the new code.

I opened the Node CMD window and ran these commands:

And the error log shows this:

And here is what is in the .Particle\Profile.json & Partilce.config.json files:

Let me know if you need anything else on my end.

The line numbers in the error log still show the line numbers from the old file.

Can you please check that you replaced C:\Users\RWB\AppData\Local\particle\node_modules\particle-cli\settings.js with this version:
https://gist.githubusercontent.com/monkbroc/589dd2c721480df90fd62aff1c8c02b4/raw/939f3bf826c722a496555c827be37477637c12d6/settings.js

@jvanier Yes I am 100% positive that I replaced the code with the new code you linked to. I checked every line of code to make sure it was the same as what you linked to.

Here is a copy of the settings.js file I now have in place here:

Here is a copy of the settings.js file: https://www.dropbox.com/s/zr4g058ex7gc5jm/settings.js?dl=0

I don’t get why the CLI is not picking up the modified settings.js with the debug logs.

The problem is clear: there is a corrupted JSON configuration file used by the CLI somewhere on your machine. If you delete this file the CLI will work again.

I just don’t know exactly where this file is. If you search your entire hard drive for profile.json and delete the file that should fix the issue.

@jvanier I did a global hard drive search for all .json files and deleted all profile.json file but it does not fix the problem.

It’s werid because even if I uninstall the Windows based CLI, then restart the computer, and then reinstall via the Windows CLI installer and the problem remains.

I guess I’ll need to wipe the hard drive and upgraded to a newer version of Windows if I want to get this working again.

Thanks for your help with this, I do apperciate it :smiley:

How do you search your harddrive?
Windows Explorer doesn’t always find files in hidden/restricted directories or in directories starting with a dot .

I used the bottom left search bar for .json files which pulled up all the .json files on the computer.

I also went directly to the .particle folder and made sure it was delete there also.

I uninstalled the Particle CLI using the uninstaller app and then reinstalled via the Windows CLI installer and this error pops up during the install also:

I have no idea what is causing this.

@jvanier FYI I wiped my MacBook Air clean and installed a new version of Windows 10.

I then installed Node JS 7.0 and Particle CLI and got errors. I then replaced Node with version 6.9.1 and reinstalled Particle CLI and it was successful :smiley:

I then installed Particle Dev successfully also :smile:

Sweet!

1 Like

Alright! I’m really puzzled why the problem was so persistent so I’m glad it is solved for you now.

I know this is a very old thread, but this just happened to me - it was working and then it stopped in an instant, and I’m a bit desperate, I have reinstalled particle CLI twice and reinstalled node js (latest version). but I still get "Unexpected token {"
I have deleted all profile.json files and deleted all *.json files in my user profile .particle\toolchains

Not sure what else to do?
Have not had this problem for the past 2 years.

1 Like