我有以下脚本:
app.js
import React from 'react'
import ReactDOM from 'react-dom'
import {Stage, Sprite} from '@inlet/react-pixi';
const App = () => (
<Stage>
<Sprite image="assets/baseBike.png" x={100} y={100}/>
</Stage>
);
ReactDOM.render(<App/>, document.body);
及以下
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<div id="stageContainer">
</div>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<script src="node_modules/pixi.js/dist/pixi.min.js"></script>
<script src="app.js" type="text/babel"></script>
</body>
</html>
现在,当我运行此命令时,控制台中没有错误,但未呈现任何内容。我也找不到我的脚本已实际加载。
如果我删除了type="text/babel"
,则会抛出一个错误:
Cannot use import statement outside a module
谁能告诉我我可能会想念什么?
更新babel
所以我注意到我缺少通天塔,但是在添加通天塔后,出现以下错误:
require is not defined
我想是因为您正在document.body
上使用ReactDOM.render
,所以您不小心删除了app.js
脚本。
尝试使用div作为安装点,以查看是否可以解决您的问题。
当您将Babel Standalone与React一起使用时,您需要配置要编译脚本的Babel预设。