How to change bootstrap version in project folder?

I installed bootstrap@3 by mistake. I meant to install v4.4.

I tried to uninstall with this cmd: npm uninstall bootstrap@3 but that didn’t work. The version in package.json and in node_modules is version 3.

Does anyone know how I can switch from one version to another?

Hello there.

What do you mean by “that didn’t work”? Do you get an error, or are you saying it is just not removing the dependency from your package.json file? If you install BootStrap4 using npm, you should be able to just point to it in the .json file.

So I tried installing latest version with: npm install bootstrap

The node_modules bootstrap folder’s bootstrap.css has this at the top:
Bootstrap v3.4.1 (https://getbootstrap.com/)

So I don’t think I can change the reference in package.json…?

It should be as easy as:

  1. Go to package.json
  2. Find bootstrap under the dependencies
  3. Replace what is there with this: "bootstrap":"^4.0.0"
  4. Run npm ci -> You could just run npm install, but I would do a clean install just for just.

Hope that helps.

1 Like

Just as an FYI, when you uninstall, you just npm uninstall bootstrap, you don’t add the version number.

And as @Sky020 says, just install the specific version you want, it will overwrite what’s there already.

1 Like

OK, and probably a dumb question, but the last step should be: npm ci bootstrap ?

No need to put bootstrap. Just run npm ci.

1 Like

After following all the steps, I checked this file again:

...\code-along\vidly\node_modules\bootstrap\dist\css\bootstrap.css

And it still says: Bootstrap v3.4.1

Do you think I should have changed the bootstrap version in package-lock.json file too…?

PS - At this point, I think I will simply start a new project since I am at the beginning phase anyway and download correct version of BS but it would be nice to know how to fix this. Packages are such a mystery to me.

It changes the entry in package.lock if you change the version. Are you sure a. something else doesn’t have a dependency on bootstrap, and that’s the entry you’re looking at, or b. that you’ve saved a specific newer version (eg you should have done npm install --save bootstrap). You are also fine to delete node modules and the lockfile, it’s not going to do any harm. So to make sure you are doing a clean install, delete the bootstrap entry in package.json, delete the modules folder, delete the lockfile, run npm install --save bootstrap (this will get bootstrap 4.4.1, which is the latest version of the package on NPM)

1 Like

Thanks everyone. I marked the last comment as solution but I think it was a group effort - thanks!

1 Like