From the beginning i have problems with nodeJs, i tried install others version but nothing resolve my problem. When i import bootstrap to my project and import any elements for example button i got this error, when I have clear react it’s work. I searching a long time for solution but nothink is work. I tried install bootstrap by npm, i used yarn, clearing cache, changing module folders.
- npm -g install npm command
ERROR
class constructors must be invoked with 'new'
renderWithHooks@http://localhost:3000/static/js/bundle.js:26679:31
mountIndeterminateComponent@http://localhost:3000/static/js/bundle.js:30650:17
beginWork@http://localhost:3000/static/js/bundle.js:31953:20
callCallback@http://localhost:3000/static/js/bundle.js:16935:18
invokeGuardedCallbackDev@http://localhost:3000/static/js/bundle.js:16979:20
invokeGuardedCallback@http://localhost:3000/static/js/bundle.js:17036:35
beginWork$1@http://localhost:3000/static/js/bundle.js:36934:32
performUnitOfWork@http://localhost:3000/static/js/bundle.js:36182:16
workLoopSync@http://localhost:3000/static/js/bundle.js:36105:26
renderRootSync@http://localhost:3000/static/js/bundle.js:36078:11
performConcurrentWorkOnRoot@http://localhost:3000/static/js/bundle.js:35473:78
workLoop@http://localhost:3000/static/js/bundle.js:43513:46
flushWork@http://localhost:3000/static/js/bundle.js:43491:18
performWorkUntilDeadline@http://localhost:3000/static/js/bundle.js:43728:25
import logo from "./logo.svg";
import "./App.css";
import "bootstrap/dist/css/bootstrap.css";
import { Button } from "bootstrap";
function App() {
return <Button className="btn btn-primary">Add</Button>;
}
export default App;
2
Answers
I am not sure if this is intentional but are you using bootstrap or react-bootstrap? because from your code you try to import vanilla bootstrap. This is maybe your issue. Try to import the button via react-bootstrap and it should work.
Reason why is simple: Bootstrap itself doesn’t provide individual components like Button in a way that can be imported directly from bootstrap as you’ve done in the original code.
Thats what react-bootstrap is for
Have you installed the react-bootstrap?