每次尝试使用“ react-bootstrap”中的某些组件时,都会出现一些奇怪的错误。这是导入“ HelpBlock”组件的一些小示例。
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;
但随后出现此错误
Attempted import error: 'react-bootstrap' does not contain a default export (imported as 'HelpBlock').
我的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"
}
}
有人可以帮助我吗?我已经重新检查了node_modules中的react-bootstrap文件夹,其中包含我要导入的组件
答案 0 :(得分:1)
您可以导入单个组件,例如:
import HelpBlock from 'react-bootstrap/HelpBlock ';
第一个是直接导入组件,以上是默认导入。默认导入与默认导出一起导出。...只能有一个默认导出。由于'react-bootstrap'不包含默认导出,因此您必须直接导入。
或import { HelpBlock } from 'react-bootstrap';
此处,将仅导入HelpBlock。希望对您有所帮助。
此article将帮助您了解es6模块。