0

I have the following Webpack and TypeScript configs:

webpack.config.js

module.exports = {
    entry: {
        dev: './src/ts/site'
    },
    output: {
        filename: './com/js/site.js'
    },
    resolve: {
        extensions: ['', '.ts', '.tsx']
    },
    module: {
        loaders: [
            // Typescript
            {
                test: /\.tsx?$/,
                loader: 'ts-loader'
            }
        ]
    }
}

tsconfig.json

{
    "compilerOptions": {
        "noImplicitAny": true,
        "module": "commonjs"
    }
}

I've simplified my project to only include the following dependencies:

package.json (partial)

"typescript": "^1.7.5",
"ts-loader": "^0.7.2",
"webpack": "^1.12.9"

When I run Webpack, I get a massive slew of errors:

enter image description here

The list goes on for many many screen lengths, but as far as I've scrolled every one is a duplicate identifier error in a .d.ts file.

What is the cause of these errors?

I've seen several similar problems both here on Stack, and across the web, but none seemed to happen in a project with just TypeScript (they all had other modules that had definition files).

From what I've gathered it may have something to do with my use of "module": "commonJS", but

  1. That would suggest that TypeScript wasn't written to work with commonJS modules
  2. I've already tried every other module type with no success

Excluding node_modules in tsconfig.json solves the problem but makes it so that installed modules can't be found in .ts files.

Sandy Gifford
  • 7,219
  • 3
  • 35
  • 65
  • it could be that there are duplicate d.ts files in your node modules (some modules depending on the same library). could you check for if the files giving errors appear more than once? – toskv Jan 05 '16 at 21:23
  • @toskv I'll take a look - but would it be telling if I've already tried deleting my entire node_modules folder and ran a fresh `npm install`? – Sandy Gifford Jan 05 '16 at 21:42
  • not really, at the moment tsc has issues if there are 2 x.d.ts files in your project, so you kind of have to take care that there's only one. :( – toskv Jan 05 '16 at 21:43
  • @toskv Just checked - the only `*.d.ts` files in the entire project (node_modules included) are in TypeScript itself (I abstracted the problem down to a simple project with almost nothing in it before asking). There are only about a dozen of those files, and they're all in the same folder (none have the same name). – Sandy Gifford Jan 05 '16 at 21:48
  • @toskv So, noob question - should I be excluding `node_modules` / only including my files specifically? Is my problem not this, but that TypeScript can't find installed modules when I **do** exclude the modules folder? – Sandy Gifford Jan 05 '16 at 21:57
  • that seems to be it. you can exclude the node_modules folder and when compiling give tsc only specific files you are depending on. it's not a very nice solution though :( – toskv Jan 05 '16 at 22:02
  • @toskv Ah, so - my problem actually has to do with my inability to import modules, not with compiling my modules folder. You've been incredibly helpful - if you'd like to type that up as an answer I'd be glad to throw you the check and +1. – Sandy Gifford Jan 05 '16 at 22:13
  • if you have a specific solution (with the changes) for your question it would probably best that you post that. I don't mind being a rubber duck. :P – toskv Jan 05 '16 at 22:14
  • 1
    @toskv Well thanks again - I think I'm at least one other question away from really getting this one solved. I'll loop back and answer it when I get it licked. over and out. – Sandy Gifford Jan 05 '16 at 22:16

0 Answers0