【问题标题】:Typescript with Babylonjs built with Webpack error: Duplicate identifier 'BABYLON'使用 Webpack 错误构建的带有 Babylonjs 的打字稿:重复标识符“BABYLON”
【发布时间】:2016-03-03 05:05:43
【问题描述】:

我正在开发一个名为 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']
  }
}

【问题讨论】:

    标签: typescript webpack babylonjs


    【解决方案1】:

    重复标识符“BABYLON”

    因为你的代码var BABYLON = require('babylonjs');。在没有根级别 importexport 的情况下,该文件将贡献于 global 命名空间,因此您有多个 var BABYLON 声明。

    修复

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

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

    【讨论】:

    • 感谢您的帮助 basarat 由于某种原因我无法使用 import BABYLON from 'babylonjs' from https://github.com/QuantumInformation/Density-Wars/blob/master/lib/game.ts#L10,我收到错误 找不到模块'babylonjs'。 我已经在 package.com 中安装了它
    猜你喜欢
    • 2017-08-01
    • 2016-09-20
    • 1970-01-01
    • 2015-09-28
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    相关资源
    最近更新 更多