4

I've just created a new project with react cli and installed npm bootstrap.

npm install bootstrap --save

I have then tried bootstrap in App.js:

import React, { Component } from 'react';
import './App.css';

class App extends Component {
  render() {
    return (
      <div>
        <div className="container">
          <h1>It Works!</h1>
        </div>
      </div>
    );
  }
}

export default App;

but it's not working.

This is my package.json:

    {
      "name": "myapp",
      "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^3.3.7",
    "react": "^15.5.4",
    "react-dom": "^15.5.4"
  },
  "devDependencies": {
    "react-scripts": "1.0.7"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

Here is my index.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1>
    <title>React App</title>
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

Is there anything else that I need to do in order to make it work?

2
  • I do not see that you have added scripts or bootstrap css inside the index html. You tried that? Commented May 31, 2017 at 21:52
  • Sorry, package.json updated Commented May 31, 2017 at 21:56

1 Answer 1

12

You installed the bootstrap npm module, but that only downloads the files to your node_modules/ directory. You haven't yet actually required bootstrap within your project itself.

Try doing this above import './App.css'

import 'bootstrap/dist/css/bootstrap.css';

You could also try linking to the bootstrap.min.cssfile in your public/index.html, if the import does not work.

Sign up to request clarification or add additional context in comments.

1 Comment

helped! Can you add how to get bootstrap js files to be working and document where it is elaborated well?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.