React-bootstrap not allowing `import {components}` syntax

廉价感情. 提交于 2019-12-25 10:05:12

问题


This is kinda weird. It works with other projects, but not with React-Bootstrap. For example;

import {Jumbotron, Button} from 'react-bootstrap';
import * as ReactBootstrap from 'react-bootstrap';

both give me a Invalid argument must be an array in all.js:12 file. However, importing like this works:

var Jumbotron = require('react-bootstrap/lib/Jumbotron');
var Button = require('react-bootstrap/lib/Button');

Sure I can use this, but it's more efficient to declare an array of components I want. Why is React-Bootstrap not supporting something so trivial?


回答1:


react-bootstrap currently don't support ES6 modules natively.

In other words, you need to do some work to be able to use ES6 imports. One way is to use a transpiler like Babel that will transpile your code from ES6 to CommonJS modules.



来源:https://stackoverflow.com/questions/40833129/react-bootstrap-not-allowing-import-components-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!