11

i rather new to mean stack and i'm trying to pull some components using bower.

I have my .bowerrc file which gives the path for installation.

//.bowerrc
 {
    "directory": "public/libs"
 }

and i have my bower.json file which looks like this:

// bower.json
{
    "name": "starter-node-angular",
    "version": "1.0.0",
    "dependencies": {
        "bootstrap": "latest",
        "font-awesome": "latest",
        "animate.css": "latest",
        "angular": "latest",
        "angular-route": "latest"   
    }
}

When i installed bower i had no problem and even the bower search is working perfect. when I'm running the command:

bower install

i get the following message:

Failed to read + path\bower.json

Unexpected token /

i get the same message when I'm trying:

bower install jquery

I tried to change the encoding of file and used json online validation tool.

any ideas??

user2656851
  • 1,643
  • 4
  • 12
  • 15
  • It is working so i guess the bower install recognize the comment sign // I think you are right about different cases. Thank you for yuor knowledge. – user2656851 Jul 02 '14 at 15:58

7 Answers7

24

Another solution is to open the file in Notepad++, go to "Encoding" and select convert to ANSI.

Best of luck

Philippe Matray
  • 1,511
  • 1
  • 13
  • 22
  • 2
    "Convert to ANSI" is all I see in Notepad++, not "ASCII". But, "Convert to ANSI" did fix the issue – Northstrider Apr 02 '15 at 18:14
  • This is strange. Reading here at http://stackoverflow.com/questions/22169387/emalformed-error-when-trying-to-register-bower-json-file I converted to UTF-8. I quoted my keys and strings and then on reading this again saved the file with ANSI. Worked. Wondering if quotes were the only issue with JSON parsing ! Umm....which is a bit confusing as json files can work with or without quotes around the keys and values if they are of single word. – HalfWebDev Dec 10 '15 at 04:16
  • The UTF-8 BOM was the real issue. You can use UTF-8 without BOM should work too. – Thomas Sep 29 '16 at 10:57
5

After creating the .bowerrc file:

  • Open the file in Visual Studio
  • Click on "Save file as" under File menu
  • Click on the down arrow sign on the right side of Save button
  • Select "Save with Encoding"
  • Agree to replace the file
  • Change the Encoding type to "Western European (Windows) - Codepage 1252" and leave the Line endings to "Current Settings"
  • Hit Save button
Lina T
  • 169
  • 2
  • 3
  • Thanks for mentioning the Visual Studio way. I didn't know this existed and was using Notepad++ for this kind of work until now. – Thomas Sep 29 '16 at 10:58
4

I had this issue due to Visual Studio adding a BOM to the start of the file. Opening it in Notepad++, going to Encoding and selecting "Encode in UTF-8 without BOM" solved the problem - the advantage of this approach over converting the file to ANSI is that you can still use Unicode characters in the Bower.json file.

Obviously you can also do this in any other text editor that supports the stripping of BOM's from a file encoded in UTF-8.

meh-uk
  • 2,031
  • 1
  • 23
  • 36
1

It may be because of a single line comment inside bower file. Comments of the form //… or /*…*/ are not allowed in JSON. So you'll get this error if you really have // bower.json line in the beginning of your bower file (like in the provided example).

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
0

Finally with a little help i got it!! Now I'm going to write the solution for others. I copied the content of bower.json from the web to sublime3 text editor. The editor added characters i can not see. copy paste to the old classic notepad and replacing the file solved it for me.

user2656851
  • 1,643
  • 4
  • 12
  • 15
0

I also had this really annoying issue. What worked for me was that I simply opened the bower.json file in Visual Studio 2017, saved the file again using Ctrl + S and that's it! I could now, for the first time, install packages via Bower!

0

Good day,

What worked for me was actually uninstalling the package i.e. in this case Bootstrap and then just including the version of Bootstrap that I wanted to use in my project in Visual Studio. See below for screenshot. I then saved and bower did its magic!!!

Bower.json

Faye
  • 1
  • 1