Installing a bower package: "no-json No bower.json file to save to"
Asked Answered
E

9

24

I've added a bower package into my project root. I'm using bower so it's easier to manage the updates for each component (one of bower's features). However I got this message after install:

no-json No bower.json file to save to

A few things:

— There is in fact a bower.json file w/i the component's folder. Should there be a global project bower.json file?

— Will this error mean the package will not update?

— The project is a WordPress project using the "WordPress-Starter-Theme" (which uses grunt to handle compass, etc). Is grunt interfering? Do I need to add anything into Gruntfile.js to manage Bower?

Thanks in advance.

Ellette answered 31/7, 2013 at 11:40 Comment(0)
C
48

You can run

bower init

to create the json file in the current directory.

Docs

Changchangaris answered 29/10, 2013 at 20:8 Comment(4)
Hello from the Future. In VS2017, where can I run this command? I started with an empty project template for asp.net core to get familiar with some of the stuff VS bundles with the mvc template.Wayless
@Zack, open up a command window in the same folder that has your *.csproj file.Helton
@Wayless under Visual Studio 2017 you need to do these steps 1. open a command prompt 2. cd to the project directory 3. run this command "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Web\External\Bower.cmd" initAquarium
Thanks :) just added the directory to my environment path.Wayless
B
7

If you're using Visual Studio (2017) you can simply do:

  • Add New Item (On the project)
  • Choose: Web -> General -> Bower Configuration File

This will not only add a bower.json file, but also the .bowerrc file. Without the .bowerrc file the packages won't be copied from the hidden 'bower_components' folder to the wwwroot/lib folder.

Buffet answered 5/1, 2018 at 22:10 Comment(1)
Thank you! Helped me a lot. Microsoft doc is missing this step.Inlaw
P
4

The bower.json file should always be in the root of your project folder. Furthermore, the file shouldn't be within the bower_components folder, because bower is responsible for creating this folder itself.

The error means that if you run bower install --save, the dependencies won't be recorded in your bower.json. This is a bad idea, because you lose the big benefit a package manager provides.

Grunt and Bower work completely independent from one-another, you don't have to change anything regarding your Grunt setup to use grunt.

Pridgen answered 5/8, 2013 at 10:6 Comment(0)
I
1

you installed on root means WP roots as you mentioned that you are trying to use Bower for your wordpress theme. So just create .bowerrc file in wordpress root and write the following code in .bowerrc file.

{
    "directory": "wp-content/themes/yourthemefolder/ui-libraries"
}

and now create bower.json also in your root and as usual write down all the dependency names there. You can read more details from Bower configuration overriding with .bowerrc

Let me know if that helps.

Insomuch answered 28/1, 2014 at 18:55 Comment(0)
P
1

If you install node via package manager with sudo apt-get install nodejs you'll also need to install nodejs-legacy with sudo apt-get install nodejs-legacy for generating bower.json in root directory

rails g bower_rails:initialize json

and for bowerfile

rails g bower_rails:initialize
Psychognosis answered 4/6, 2016 at 9:9 Comment(0)
S
0

Be sure to remove unnecessary white-spaces or extra line breaks to avoid getting the error "Neither bower.json nor component.json present"

Also as mentioned above, be sure to run bower install, or bower-installer command in the directory where your bower.json file is located.

Works for both bower and bower-installer

Skywriting answered 18/1, 2015 at 15:10 Comment(0)
H
0

I figured out that what was causing the error is installing the component in the wrong directory. Just make sure the file path in the command line points to the respective directory.In my case C:\Users\Nick\Documents\myprojectfolder>..commands..

Hilburn answered 16/4, 2017 at 15:51 Comment(0)
A
0

In Visual Studio 2017 you need to do this

  1. open a command prompt
  2. cd to the project directory
  3. run this command "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Web\External\Bower.cmd" init
Aquarium answered 31/12, 2017 at 18:36 Comment(0)
C
-1

I resolved this issue with:

npm install -g bower
Clearcole answered 24/9, 2019 at 13:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.