Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

class constructors must be invoked with 'new'

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;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading