0

I have some weird error everytime when I'm trying to use some component from 'react-bootstrap'. Here is some small example where I'm importing "HelpBlock" component.

import PropTypes from 'prop-types';
import React from 'react';
import HelpBlock from 'react-bootstrap';

class RegisterFormDetails extends React.Component {

...
              <HelpBlock>{validationErrorMessage}</HelpBlock>
            }
          </div>
        </div>
    );
      };
export default RegisterFormDetails;

but then I'm getting this error

Attempted import error: 'react-bootstrap' does not contain a default export (imported as 'HelpBlock').

my package.json

    {
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {},
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "bootstrap": "^4.3.1",
    "lodash": "^4.17.11",
    "prop-types": "^15.7.2",
    "react": "^16.8.3",
    "react-bootstrap": "^0.32.1",
    "react-bootstrap-sweetalert": "^4.4.1",
    "react-dom": "^16.8.3",
    "react-scripts": "^2.1.5",
    "react-select": "^2.4.1"
  }
}

somebody can help me ? I have rechecked the react-bootstrap folder in node_modules and contains the component which I'm trying to import

2
  • 1
    try this import { HelpBlock } from 'react-bootstrap'; and check this stackblitz.com/edit/react-kge48i ! Commented Mar 3, 2019 at 14:04
  • thanks. I'm so stupid Commented Mar 3, 2019 at 14:19

1 Answer 1

1

You can import individual components like:

import HelpBlock from 'react-bootstrap/HelpBlock ';

The first one is importing component directly, The above is a default import. Default imports are exported with export default .... There can be only a single default export. Since 'react-bootstrap' does not contain a default export , you have to import directly.

or import { HelpBlock } from 'react-bootstrap';

Here, only HelpBlock will be imported. Hope it helps.

This article will help you to understand es6 modules.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.