React-bootstrap不允许`import {components}`语法 [英] React-bootstrap not allowing `import {components}` syntax
问题描述
import {Jumbotron,Button} from'react-bootstrap';
import *作为ReactBootstrap从'react-bootstrap';
都给我一个无效参数必须是数组
在 all.js:12
文件。但是,这样的导入可以起作用:
var Jumbotron = require('react-bootstrap / lib / Jumbotron');
var Button = require('react-bootstrap / lib / Button');
当然可以使用这个,但是更有效地声明一组我想要的组件。为什么React-Bootstrap不支持那么简单的东西?
react-bootstrap
目前本机不支持ES6模块。
换句话说,您需要做一些工作才能使用ES6导入。一种方法是使用像 Babel 这样的透明物,它将将您的代码从ES6转移到CommonJS模块。
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?
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.
这篇关于React-bootstrap不允许`import {components}`语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!