【发布时间】:2020-09-29 22:21:53
【问题描述】:
我需要什么来完成以下工作?
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<script type="text/babel">
import React from 'react';
</script>
</body>
</html>
在其当前形式中会产生错误:
Inline Babel script:2 Uncaught ReferenceError: require is not defined
at <anonymous>:3:14
at run (babel.js:61531)
at check (babel.js:61597)
at loadScripts (babel.js:61638)
at runScripts (babel.js:61668)
at transformScriptTags (babel.js:336)
at babel.js:327
这个表格也不行:
import React from 'react.production.min';
【问题讨论】:
-
这能回答你的问题吗? Do I need require js when I use babel? --- 虽然我不知道这个问题是否涉及非转译代码。
-
由于您不在模块上下文中,您可以直接使用
React,因为它是通过直接链接脚本在全局对象上定义的。 -
@evolutionxbox 该链接绝对是有价值的信息,但我认为它不能回答问题。
-
我已将其更改为堆栈 sn-p。 ????
-
好的,现在我知道 stack sn-ps 是 StackOverflow 上的一种格式,而不是一些可以帮助我调试 JavaScript 的浏览器功能。
标签: javascript reactjs