0

can we import bootstrap.bundle.js file directly from node_modules/boostrap directory?

import "bootstrap/dist/css/bootstrap.rtl.min.css";

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Script src="node_modules/bootstrap/dist/js/bootstrap.bundle.js"></Script>
      <Component {...pageProps} />
    </>
  );
}

export default MyApp;

how can I point to node_modules directory inside the src attribute?

0

1 Answer 1

1

Recently I started learning Next.js and was stuck adding Bootstrap Bundle JS. So, one can do this way using the useEffect hook:

import "bootstrap/dist/css/bootstrap.rtl.min.css";

function MyApp({ Component, pageProps }) {

  useEffect(() => {
    if (typeof window !== undefined) {
      const bootstrap = require('bootstrap/dist/js/bootstrap.bundle.min.js')
    }
  })

  return (
    <>
      <Component {...pageProps} />
    </>
  );
}

export default MyApp;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.