Closed
Description
I am building an app using create-react-app and bootstrap. But I am not able to import bootstrap in my app. I tried including it in index.html like this:
<script src="lib/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="lib/css/bootstrap.min.css">
but it does not work.
So, how can I import bootstrap in my app? Thanks
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
dharmesh-khandelwal commentedon Jul 26, 2016
Turns out, I have to add
src/
to the source, I did this and it worked in development.gaearon commentedon Jul 26, 2016
Let's keep it open for now. I want to make sure this works well both for development and production, and that we document it.
dharmesh-khandelwal commentedon Jul 26, 2016
Well, if react-router is being used, then above method will work only for the home route. Finally, I settled with the following in index.html:
For me, this works for all the routes.
For production, I think we need to copy that lib (vendor/assets) folder from src to the build directory. #28
gaearon commentedon Jul 26, 2016
Yes, this will be a part of #28. I will look at it this week.
taion commentedon Jul 26, 2016
For the CSS it should probably be
BTW.
Bootstrap ships built CSS in their npm package.
scwood commentedon Jul 28, 2016
How can I get this to work? When I npm install bootstrap and use that import statement, it says the loader can't parse the file correctly.
SpencerCDixon commentedon Jul 28, 2016
It's probably failing on the fonts that need to be loaded properly. Does the create-react-app's webpack config include the appropriately font loaders?
scwood commentedon Jul 28, 2016
The weird thing is if I move bootstrap.css directly into my src folder and import it relatively it works fine... any ideas?
taion commentedon Jul 28, 2016
Sounds like
paths.appNodeModules
is broken here: https://github.com/facebookincubator/create-react-app/blob/ca7d227ae0354e04941ba0e4f76c0bcbf3050dfa/config/webpack.config.dev.js#L55.taion commentedon Jul 28, 2016
Oh, it was fixed in #178.
gaearon commentedon Jul 28, 2016
The fix will be out in 0.2.0 but you can try using alpha for now: #190
isaklafleur commentedon Jun 9, 2017
@taion answer helped me, but maybe anyone are interested in a bit more detailed instruction so here it goes... ;)
I'm using React 15.5.4...
index.js
App.js
Robust1308 commentedon Jun 14, 2017
Import Bootstrap CSS by adding
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
is working fine, but how about the Bootstrap JS can I do the same?Because I got a problem with BootStrap JS in React-Component
You can view the problem here: https://stackoverflow.com/questions/44539398/react-scripts-import-bootstrap-not-working?noredirect=1#comment76072289_44539398
FDiskas commentedon Jun 30, 2017
Still wandering why in create react app there is no scss support. People are using this for ages and this could solve this issue
cr101 commentedon Jun 30, 2017
@FDiskas Currently there is support for pre-processors (from SASS to CSS) but unfortunately, you can can't include the
.scss
files. Hopefully, SASS support will come soon.franzitobambino commentedon Aug 23, 2017
HAS SASS support come as yet?
FDiskas commentedon Sep 7, 2017
@jacoahmad which creat-react-app version you are using?
subelsky commentedon Nov 4, 2017
I followed @isaklafleur's advice but node complained about importing a file that was outside of
src/
. I had to do this to make it work:pimvanderheijden commentedon Dec 27, 2017
@subelsky
How will you proceed in production?
cool88 commentedon Jan 2, 2018
I want to include the bootstrap from the CDN to divert the bandwidth from my own server instead of including it using a node_module. Does the question make sense?
Timer commentedon Jan 2, 2018
@cool88 edit your
public/index.html
and add the required script/link tags 😄I'll lock this issue because it's hard to track things in old issues. Please file a new issue if you need help.