After installing bootstrap with npm install bootstrap I added the style to /pages/_app.js like so:
import 'bootstrap/dist/css/bootstrap.css';
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
However anything from it that uses javascript does not work at all, e.g. the Collapse example from their docs.
function App() {
return (
<div>
<p>
<a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-bs-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
</div>
</div>
</div>
);
}
export default App
If I add import 'bootstrap/dist/js/bootstrap.js' to /pages/_app.js then it starts "working" as expected, until a page reload in which it says ReferenceError: document is not defined (screenshot), which leads me to believe it's not possible or that I shouldn't try to use boostrap + react or next.js.
I had thought them dropping jquery meant that it should work just "out of the box" with frameworks like react (as in not needing react-boostrap or reactstrap anymore)
Is there a way to properly use boostrap 5 and nextjs? Or should I just try something else entirely or go back to using reactstrap (which currently seems to only support boostrap 4)?




