React-Bootstrap Uncaught ReferenceError:未定义require [英] React-Bootstrap Uncaught ReferenceError: require is not defined

查看:159
本文介绍了React-Bootstrap Uncaught ReferenceError:未定义require的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的响应者,我正在尝试在项目中使用react-bootstrap。但是我无法使它工作,在 https://的react-bootstrap页面上的示例react-bootstrap.github.io/getting-started.html 。我只在html中包含以下代码,但出现了 react.production.min.js:10 Uncaught ReferenceError:require not defined 错误。实际上,我已经阅读了其他问题和许多教程,甚至还不能包含来自CDN的正确文件。什么应该是正确的文件,或者我需要其他任何脚本才能正常工作。
谢谢

I am new to react, I am trying to use react-bootstrap in a project. However I could not get it worked, the example on react-bootstrap page at https://react-bootstrap.github.io/getting-started.html. I only included below code in my html, but I am getting react.production.min.js:10 Uncaught ReferenceError: require is not defined error. Actually I have read other questions and many tutorials, still could not even include correct files from cdn. What should be the correct files or do I need to any other scripts to get it worked. Thank you,,


<!-- Bootsrap and react js-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/cjs/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.31.5/react-bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/cjs/react-dom.production.min.js"></script>

下面是完整的错误跟踪:

Full error trace is below :

Uncaught ReferenceError: require is not defined
at react.production.min.js:10
 react-bootstrap.min.js:10 Uncaught TypeError: Cannot read property    'Component' of undefined
at Object.e.__esModule.default (react-bootstrap.min.js:10)
at t (react-bootstrap.min.js:1)
at Object.e.__esModule.default (react-bootstrap.min.js:11)
at t (react-bootstrap.min.js:1)
at Object.t.exports (react-bootstrap.min.js:1)
at t (react-bootstrap.min.js:1)
at t (react-bootstrap.min.js:1)
at react-bootstrap.min.js:1
at react-bootstrap.min.js:1
at react-bootstrap.min.js:1

react-dom.production.min.js:13未捕获的ReferenceError:在react-dom.production.min.js:13中未定义require

1: 86 Uncaught ReferenceError:未定义ReactBootstrap
,时间为1:86

react-dom.production.min.js:13 Uncaught ReferenceError: require is not defined at react-dom.production.min.js:13 1:86 Uncaught ReferenceError: ReactBootstrap is not defined at 1:86

推荐答案

如果使用的是在浏览器中,除非您使用的是webpack或类似工具,否则请不要遵循CommonJS部分。浏览器是异步的,因此您不能同步使用 require 。请遵循ES6(如果使用Babel进行转译)或AMD(使用RequireJS或类似代码)的说明。

If you are using it in a browser, don't follow the CommonJS section until you are using webpack or something similar. Browsers are asynchronous, therefore you cannot use require synchronously. Follow the ES6 (if you are transpiling with Babel) or AMD (with RequireJS or similar) instructions instead.

如果您不知道这些含义是什么,请遵循浏览器全局变量说明包括所有内容:

If you don't know what any of those mean, follow the "Browser globals" instructions to include everything:

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/<react-version>/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/<react-version>/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/<version>/react-bootstrap.min.js"></script>
<script>
var Alert = ReactBootstrap.Alert;
</script>

这篇关于React-Bootstrap Uncaught ReferenceError:未定义require的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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