React-bootstrap不允许`import {components}`语法 [英] React-bootstrap not allowing `import {components}` syntax

查看:161
本文介绍了React-bootstrap不允许`import {components}`语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪。它与其他项目配合使用,但不适用于React-Bootstrap。例如;

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆