TypeError: Class constructor {class} cannot be invoked without 'new'

Viewed 2673

When running a create-react-app app with react-bootstrap installed, I am getting this error below when trying to add a Button

TypeError: Class constructor Button cannot be invoked without 'new'

My imports are like this:

import 'bootstrap/dist/css/bootstrap.min.css';
import './App.css';
import PropTypes from "prop-types";
import { Button } from "bootstrap";
import { PureComponent } from "react";

and the render code:

  render() {
    return (
      <div className="App">
        <header />
        <Button>Test</Button>
        ...

I have looked into lots of other questions talking about Babel, Webpack, and a compiler config. But I am not seeing all these configurations inside my create-react-app.

1 Answers

So, I found the problem. After 1 hour lost. The mistake was on the suggested import that I've added.

Wrong:

import { Button } from "bootstrap";

Right:

import { Button } from "react-bootstrap";
Related