我使用pixijs开始了一个小项目。我遵循该教程:https://www.youtube.com/watch?v=FrnXCZmmAZo,但对我而言不起作用。
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<script src="./node_modules.js/pixi.js/dist/pixi.min.js"></script>
<body>
<script src="index.js" type="module"></script>
</body>
我使用以下命令获得了pixi模块:npm install pixi.js
index.js:
import * as PIXI from './node_modules/pixi.js/dist/pixi.min.js';
const log = console.log;
const app = new PIXI.Application();
错误:
PIXI.Application is not a constructor[En savoir plus] index.js:4:13
<anonyme>
http://localhost:3000/index.js:4:13
InnerModuleEvaluation self-hosted:4290:5 evaluation self-hosted:4243:9
更新
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<script src="./node_modules.js/pixi.js/dist/pixi.min.js"></script>
<script src="index.js" type="module"></script>
</body>
</html>
index.js:
const log = console.log;
const app = new PIXI.Application();
错误:
PIXI is not defined
答案 0 :(得分:1)
本教程不使用模块。
PIXI
在全球公开:https://github.com/pixijs/pixi.js/blob/v4.8.1/src/index.js#L51
如果您删除导入,并在脚本标签中修复了错字,则应该可以。
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<script src="./node_modules/pixi.js/dist/pixi.min.js"></script>
<script src="index.js" type="module"></script>
</body>
</html>
index.js:
const log = console.log;
const app = new PIXI.Application();
答案 1 :(得分:0)
如果您使用的是 npm,我会收到此错误,因为我运行的是 npm install pixi
(不正确)而不是 npm install pixi.js
(正确)。