【发布时间】:2017-06-01 19:52:50
【问题描述】:
运行我的代码时出现以下错误: 未捕获的 ReferenceError:未定义三个
module game {
export class Add3DScene extends dragonwings.Command {
@inject('ResponsiveDiv') protected _responsiveDiv: components.ResponsiveDiv;
public execute(): void {
super.execute();
var scene = new THREE.Scene();
}
}
}
我无法尝试this 解决方案,因为我无权访问嵌入的 html
然而,我尝试过 this,但添加 shim 似乎没有帮助,而且由于不了解如何将其合并到我的打字稿中,我无法添加定义包装器。
我可以看到在 chrome 调试器中加载了three.min.js
我正在使用 requirejs,这似乎会导致我在网上找到的一些复杂情况。这是我的配置的简化版本
requirejs.config({
baseUrl: "content/${gamecode}/lib",
paths: {
TweenMax: "gsap/TweenMax",
THREE: "three/three.min",
},
shim:
{
'THREE': {
exports: 'THREE'
},
'game_libs': {
deps: ['stats', 'TweenMax']
},
'../app/js/main': {
deps: ['game_libs']
},
}
});
任何帮助表示赞赏
**编辑 在查看Require.js not loading Three.js 之后,我的其他模块不再定义,所以我还没有开始执行我最初发布的代码 新的需要配置
define("three-glue", ["three"], function (three) {
window.THREE = three;
return three;
});
requirejs.config({
baseUrl: "content/${gamecode}/lib",
waitSeconds: 60,
paths: {
TweenMax: "gsap/TweenMax",
three: "three/three.min",
},
map: {
'*': {
three: 'three-glue'
},
'three-glue': {
three: 'three'
},
shim:
{
'game_libs': {
deps: [
'TweenMax'
]
},
'../app/js/main': {
deps: ['game_libs']
},
}
}
});
【问题讨论】:
-
你有本地的库代码吗?
-
是的,我已经手动将 three.min.js 复制到项目中(加载成功)并通过 npm install --save @types/three 包含我的定义文件
-
你是否使用了three.js 映射文件以便打字稿能够识别它?
-
您需要在生成的模块的 require 调用中导入需要注入的模块。尝试添加 import 'THREE';在你的模块顶部
标签: typescript three.js requirejs