简体   繁体   中英

fail to start typescript compiled file

I have converted big JS project to typescript (as IC# programmer) using in PhantomJs. The problem is interpreter (phantomjs) fails while executing this js file.

D:\My\phantomjs-1.9.7-windows\phantomjs.exe --load-images=false --ssl-protocol=any --web-security=no --cookies-file=cookies C:\Users\alex\Projects\robot\bo.js
TypeError: 'undefined' is not an object (evaluating 'b.prototype')

the code is:

var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]
    function __() { this.constructor = d; }
    __.prototype = b.prototype; // <<< here
    d.prototype = new __();
};

So. I think the problem is somewhat related to inheritance. Have any one encountered this problem? Any help is appreciated. Thanks.

The most common cause of this error is that you are loading the files in the wrong order... for example...

File A

class ExampleClass {
    someMethod() {
        alert('Hello World');
    }
}

File B

class ExampleSubClass extends ExampleClass {

}

If you were to load File B before File A , you would get the exact error you are describing. (This includes forgetting to load File A or loading File A after File B ).

Fixes

If you are combining all of your files into a single file (and you are probably using a _references.ts file) make sure the references are in the right order.

/// <reference path="file-a.ts" />
/// <reference path="file-b.ts" />

If you are using script tags, it is the similar fix (making sure you are using .js extensions and checking the order of loading)...

<script src="file-a.js"></script>
<script src="file-b.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM