简体   繁体   English

“EMALFORMED无法读取bower.json”“意外令牌/”

[英]“EMALFORMED Failed to read bower.json” “unexpected token /”

i rather new to mean stack and i'm trying to pull some components using bower. 我宁愿新手意味着堆栈而我正在尝试使用bower来拉动一些组件。

I have my .bowerrc file which gives the path for installation. 我有我的.bowerrc文件,它提供了安装路径。

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

and i have my bower.json file which looks like this: 我有我的bower.json文件,如下所示:

// 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. 我试图改变文件的编码并使用json在线验证工具。

any ideas?? 有任何想法吗??

Another solution is to open the file in Notepad++, go to "Encoding" and select convert to ANSI. 另一个解决方案是在Notepad ++中打开文件,转到“编码”并选择转换为ANSI。

Best of luck 祝你好运

After creating the .bowerrc file: 创建.bowerrc文件后:

  • Open the file in Visual Studio 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" 将编码类型更改为“西欧(Windows) - 代码页1252”并将行结尾保留为“当前设置”
  • Hit Save button 点击保存按钮

I had this issue due to Visual Studio adding a BOM to the start of the file. 由于Visual Studio在文件的开头添加了BOM,因此我遇到了这个问题。 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. 在Notepad ++中打开它,转到编码并选择“在没有BOM的UTF-8中编码”解决了这个问题 - 这种方法优于将文件转换为ANSI的优点是你仍然可以在Bower.json文件中使用Unicode字符。

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. 显然,您也可以在支持从UTF-8编码的文件中剥离BOM的任何其他文本编辑器中执行此操作。

It may be because of a single line comment inside bower file. 这可能是因为bower文件中的单行评论 Comments of the form //… or /*…*/ are not allowed in JSON. 在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). 因此,如果你真的在bower文件的开头有// bower.json行,你会得到这个错误(就像在提供的例子中一样)。

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. 我将bower.json的内容从web复制到sublime3文本编辑器。 The editor added characters i can not see. 编辑添加了我看不到的字符。 copy paste to the old classic notepad and replacing the file solved it for me. 将粘贴复制到旧的经典记事本中,替换文件为我解决了问题。

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! 对我有用的是我只是在Visual Studio 2017中打开了bower.json文件,使用Ctrl + S再次保存文件就是这样! I could now, for the first time, install packages via Bower! 我现在可以第一次通过Bower安装包装!

Good day, 美好的一天,

What worked for me was actually uninstalling the package ie in this case Bootstrap and then just including the version of Bootstrap that I wanted to use in my project in Visual Studio. 对我有用的实际上是卸载软件包,在本例中是Bootstrap,然后只包括我想在Visual Studio中的项目中使用的Bootstrap版本。 See below for screenshot. 请参阅下面的截图。 I then saved and bower did its magic!!! 然后我保存并且凉亭做了它的魔力!

Bower.json Bower.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM