1

Closed

error in compiler: Unable to get property 'toLowerCase' when building a simple 2 file 'project'

description

This may well be something I'm doing wrong, but the compiler should help guide me as to what it is I have wrong (or possibly this is a bug)


When I construct two files (project) as such.
./main.ts
./utils/helpers.ts
where the contents of each file is

./main.ts
import utils = require("./utils/helpers.ts");

utils.log("hello");
./utils/helpers.ts
module utils {

    export function log(args) {
        console.log(args);
    }

}
I then run tsc Version 0.9.1.1 with this command

tsc .\Main.ts --module

I get the following error:
tsc.js(55958, 21) JavaScript runtime error: Unable to get property 'toLowerCase' of undefined or null reference
Any thoughts?
Closed Aug 27, 2013 at 8:24 PM by RyanCavanaugh
This has been fixed in the develop branch

comments

staxmanade wrote Aug 27, 2013 at 4:38 AM

I worked it out (to get the compiler happy) but only got it to work with the VS tooling where it inferred the project. Still can't get the command-line to work with this sample.


file paths remained the same but the code in each file changed.

utils/helpers.ts
export module utils {
    export function log(args) {
        console.log(args);
    }
}
main.ts
import utilsMod = require("./utils/helpers");

var utils = utilsMod.utils;

utils.log("hello");

staxmanade wrote Aug 27, 2013 at 4:46 AM

Ok, I looked at typescript.js at the line# in my file and realized that I am supposed to pass in a value to the --module parameter.


Might I suggest on the set: below that the argument is checked and possibly throw a helpful exception as to usages of the --module?
        opts.option('module', {
            usage: {
                locCode: TypeScript.DiagnosticCode.Specify_module_code_generation_0_or_1,
                args: ['commonjs', 'amd']
            },
            type: TypeScript.DiagnosticCode.KIND,
            set: function (type) {
                type = type.toLowerCase();

                if (type === 'commonjs') {
                    _this.compilationSettings.moduleGenTarget = 1 /* Synchronous */;
                } else if (type === 'amd') {
                    _this.compilationSettings.moduleGenTarget = 2 /* Asynchronous */;
                } else {
                    _this.addDiagnostic(new TypeScript.Diagnostic(null, 0, 0, TypeScript.DiagnosticCode.Module_code_generation_0_not_supported, [type]));
                }
            }
        }, 'm');