ryan
ryan

Reputation: 6655

Visual Studio always reporting module errors but node compiler works when all typescript files specified

I recently updated my project from 0.8.3 to 0.9.5. I am compiling to ES3 and using AMD. I do not combine the JS into a single file. At development time I load the modules dynamically using RequireJS. At compile time I use the RequireJS optimizer for single file generation.

After refactoring a few things I am stuck at two distinct errors (several occurrences).

Module cannot be aliased to a non-module type.
Unable to resolve external module '...'

I have 84 typescript files and 21 definition files in my project. When using the node compiler I am able to pass in all 105 ts/d.ts files in any order and it compiles the JS for each without any errors or warnings. However, when I only specific a single ts file with the node compiler I am able to see the same module import errors that VS shows.

I read about _references.ts but I'm not sure that will help me in my scenario as it reads like it will only be used when using the --out option.

I compared my .csproj with a basic HTML TypeScript application one and I noticed that mine has several DependentUpon entries that new typescript project does not (see below). I'm not sure if these are harmful or not. My project type is a Class Library but I correctly setup the TypeScript Build settings tab as well as Tools->Options->Text Editor->TypeScript->Project.

<Content Include="js\controls\abc\models\xyz\baseRow.js">
  <DependentUpon>baseRow.ts</DependentUpon>
</Content>

I want to take advantage of VS's error reporting but I am unsure how to resolve these errors at this point. Any suggestions are appreciated

Upvotes: 3

Views: 1410

Answers (2)

Drew Noakes
Drew Noakes

Reputation: 311275

I experienced the same issue when having two files of the same name but with different casing. Coming from MS, TypeScript probably doesn't support this (Windows files/paths are case-insensitive.)

Upvotes: 0

ryan
ryan

Reputation: 6655

I found the problem. The top of my typescript files have mixed ///<reference... and imports such as:

///<reference path="../../../vendor/underscore/underscore.d.ts"/>
import _ = require("underscore")
///<reference path="../../../vendor/jquery/jquery.d.ts"/>
import $ = require("jql")

///<reference path="../templates/templates.d.ts"/>
import ET = require("text!controls/research/templates/edits-pane/result.html")

Most of my .d.ts files have ambient module declarations inside of them. Once I moved all of the ///<reference to the top, VS stopped throwing errors and started compiling as expected.

///<reference path="../../../vendor/underscore/underscore.d.ts"/>
///<reference path="../../../vendor/jquery/jquery.d.ts"/>
///<reference path="../templates/templates.d.ts"/>
import _ = require("underscore")
import $ = require("jql")

import ET = require("text!controls/research/templates/edits-pane/result.html")

I'm not sure if this is by design or not. Hope it helps someone else.

Upvotes: 4

Related Questions