0

I have a website created using vanilla Js. Now, I am trying to add React to it. I followed the steps from the official documentation (https://reactjs.org/docs/add-react-to-a-website.html). Everything works fine. I am able to use react in my project. But now, I need to use a react library (react-responsive-carousel).

I tried running npm install react-responsive-carousel. But I am not able to import this in my React component.

I compile my react files using npx babel react-js --out-dir js --presets @babel/preset-env,@babel/preset-react --watch. It compiles the react import statements into require statements and I get the error "Uncaught ReferenceError: require is not defined" in tthe browser

How can I use react libraries in my project?

1 Answers1

0

Do you have package file in you project? I think you can initialize npm and once you have package file,you can install the packages. Note- You should have node js installed

  • Also on the same page (https://reactjs.org/docs/add-react-to-a-website.html) check section to add JSX to project. These are same steps I mentioned above – Praneet Rane Mar 16 '23 at 14:21
  • 1
    I have already added this. I can install packages using npm but error is in the import statement. – Hitesh Jindal Mar 16 '23 at 14:27