使用Webpack错误构建的Babylonjs的Typescript:重复的标识符' BABYLON'

时间:2015-11-29 14:14:21

标签: typescript webpack babylonjs

我正在开发名为density wars的webgl RTS游戏,但我收到了很多错误,如下所示:

ERROR in [default] /Users/nikos/PhpstormProjects/Density-Wars/babylonjs.d.ts:1:15 Duplicate identifier 'BABYLON'.

在我的打字稿入口点,我这样做:

/// <reference path="./gameUnits/Core.ts" />
/// <reference path="./utils/UnitCommand.ts" />
/// <reference path="./utils/Formations.ts" />
/// <reference path="./User.ts" />
declare function require(module: string):any

require('../style.css');
var BABYLON = require('babylonjs');

webpack.config:

module.exports = {
  context: __dirname + "/lib",
  entry: {
    main: [
      "./game.ts"
    ]
  },
  output: {
    path: __dirname + "/dist",
    filename: "density-wars.js"
  },
  devtool: "source-map",
  module: {
    loaders: [
      {
        test: /\.ts$/,
        loader: 'awesome-typescript-loader'
      },
      { test: /\.css$/, loader: "style-loader!css-loader" }
    ]
  },
  resolve: {
    // you can now require('file') instead of require('file.js')
    extensions: ['', '.js', '.json']
  }
}

1 个答案:

答案 0 :(得分:2)

  

重复标识符'BABYLON'

由于您的代码var BABYLON = require('babylonjs');。如果没有根级别importexport,则该文件会为全局命名空间做出贡献,因此您有多个var BABYLON声明。

修复

使用import BABYLON = require('babylonjs');或至少export来自包含var BABYLON的文件的内容。

更多https://basarat.gitbooks.io/typescript/content/docs/project/modules.html