This project is read-only.

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

Topics: General
Dec 27, 2013 at 3:59 PM
Edited Dec 27, 2013 at 4:46 PM
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">
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
Dec 27, 2013 at 8:53 PM
Which line of code is generating that error?

Regarding the <Content> element, as of version 0.9 TypeScript no longer includes the generated JavaScript in the project. You should simply delete baseRow.js and all other .js files that have a corresponding .ts file. Just think of the JavaScript as output, similar to a compiled dll.
Dec 27, 2013 at 9:09 PM
Edited Dec 27, 2013 at 9:11 PM
From one of my .d.ts files I have the following. This from controls/abc/templates/templates.d.ts
declare module "text!controls/abc/templates/xyz.html" { }
And then in the .ts file I have the import. This from controls/abc/views/someView.ts
///<reference path="../templates/templates.d.ts"/>
import someViewTemplate = require("text!controls/abc/templates/someView/empty.html")
The error is on the import statement line. I have mirrored this setup in a basic HTML TypeScript app and am able to import "text!..." controls with this setup.

I am convinced that this is not a code error as it compiles with the node tsc compiler. I don't want to guess, but if I had to I'd say that VS is starting from one of my top level ts files, tracing the dependencies, and then a reference directive is either ignored or the path is incorrectly resolved.
Dec 31, 2013 at 5:21 PM
I'm trying to reproduce your issue and don't see any problem. (Though I notice above you are declaring a different path than you are importing - I assume you are declaring the module you are importing in your problem solution?)

If you can provide more info (preferably a solution that reproduces this problem), then please open an issue on the "Issues" section of this project and someone will take a look into it further.

Jan 2, 2014 at 7:20 PM
I found the problem. I used to have the top of my typescript files have mixed ///<references... 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 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 but I feel two things should happen -- this should be communicated in the 0.9.x upgrade notes and the VS tooling should provide a better indication of the error. Before I refactored there was no indication that this was the problem.