首页 > 解决方案 > 用 react.js 加载 ammo.js

问题描述

我在我想要加载的 reactjs 应用程序中有一个自定义 ammo.js 构建,在 typescript 中。不幸的是,它不起作用。

我不得不抑制 eslint,更漂亮的是不使用 ammojs api 应用它。

反应js v16

import * as Ammo from './ammo.js';
Ammo().then (console.log('ammojs loaded'));

我有这个错误:

无法编译
/home/sancelot/git/courbes-simulation/src/components/Child.tsx
TypeScript 错误在 /home/sancelot/git/courbes-simulation/src/components/Child.tsx(10,1):
这个表达式不可调用。
类型“typeof Ammo”没有呼叫签名。TS2349
8 | // @ts-忽略
9 | 从'./ammo.js'导入*作为弹药;

10 | Ammo().then (console.log('ammojs loaded'));
| ^
11 |
12 |
13 | type Props = {
此错误发生在构建期间,无法解除。

标签: javascriptreactjstypescriptammo.js

解决方案


由于这是一个错误编译,添加 @ts-ignore 解决了这个问题。


推荐阅读