0

I'm working on a webgl RTS game called density wars, but I am getting lots of errors like the following:

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

In my entry point to typescript I do this:

/// <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']
  }
}
Nikos
  • 7,295
  • 7
  • 52
  • 88

1 Answers1

2

Duplicate identifier 'BABYLON'

Because of your code var BABYLON = require('babylonjs');. In the absence of a root level import or export the file is contributing to the global namespace and thus you have multiple var BABYLON declarations.

Fix

use import BABYLON = require('babylonjs'); Or at least export something from the file that has the var BABYLON.

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

basarat
  • 261,912
  • 58
  • 460
  • 511
  • Thanks for your help basarat for some reason I can't use **import BABYLON from 'babylonjs'** from `https://github.com/QuantumInformation/Density-Wars/blob/master/lib/game.ts#L10`, I am getting the error **Cannot find module 'babylonjs'.** I have installed it in package.com – Nikos Dec 10 '15 at 18:47