barbatus/typescript-runtime

Issues after upgrading from Meteor 1.4.4.2 to Meteor 1.5

Closed this issue · 8 comments

I'm having the following stacktrace in my client code after upgrading from Meteor 1.4.4.2 to Meteor 1.5. The dependency on typescript runtime was upgraded from 1.0.0 to 1.0.1; I tried a downgrade with no success:

barbatus_typescript-runtime.js?hash=b9c22e4…:134 Uncaught TypeError: Object.setPrototypeOf called on null or undefined
    at setPrototypeOf (<anonymous>)
    at __extends (barbatus_typescript-runtime.js?hash=b9c22e4…:134)
    at project-selector.component.ts:91
    at project-selector.component.js (project-selector.component.ts:101)
    at fileEvaluate (modules-runtime.js?hash=8587d18…:343)
    at require (modules-runtime.js?hash=8587d18…:238)
    at component-selector.component.js (component-selector.component.ts:14)
    at fileEvaluate (modules-runtime.js?hash=8587d18…:343)
    at require (modules-runtime.js?hash=8587d18…:238)
    at shared.module.js (shared.module.ts:15)
    at fileEvaluate (modules-runtime.js?hash=8587d18…:343)
    at require (modules-runtime.js?hash=8587d18…:238)
    at work-item-modal.component.js (work-item-modal.component.ts:23)
    at fileEvaluate (modules-runtime.js?hash=8587d18…:343)
    at require (modules-runtime.js?hash=8587d18…:238)

The code in the project-selector.component.ts:

import { Mongo } from 'meteor/mongo';
import { Component, EventEmitter, AfterContentInit, AfterViewChecked, ElementRef, forwardRef, OnInit } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { KitsuneComponent } from 'imports/ui/kitsune.component';
import { Project, Projects } from 'imports/api/project/project';
import * as _ from 'lodash';

export abstract class SelectorComponent<T> extends KitsuneComponent implements ControlValueAccessor, AfterContentInit, AfterViewChecked {
  selected: T | T[];
  settings: any;
  select: EventEmitter<T | T[]> = new EventEmitter<T | T[]>();

  protected dropdown: JQuery;
  protected onTouched: () => void;

  constructor(private element: ElementRef) {
    super();
  }

  ngAfterContentInit() {
    this.dropdown = jQuery(this.element.nativeElement).dropdown(_.assign(this.settings || {}, {
      onChange: (val: string | string[]) => {
        // TODO setting this.selected value will fail on safari for this and writeValue()
        this.selected = _.isArray(val) ? val.map(_ => this.getItem(_)) : this.getItem(val);
        this.select.emit(this.selected);
      }
    }));
  }

  removeSelected(item: any) {
    let deletingItem = typeof item === "string" ? item : item.toString();
    this.dropdown.dropdown("remove selected", deletingItem);
  }

  ngAfterViewChecked() {
    this.setValue();
  }

  writeValue(item: T | T[]): void {
    this.selected = item;
  }

  registerOnChange(fn: (_: T | T[]) => void): void {
    this.select.subscribe(fn);
  }

  registerOnTouched(fn: () => void): void {
    this.onTouched = fn;
  }

  getValue(item: T): string {
    return item.toString();
  }

  getItem(val: string): T {
    return <any>val;
  }

  protected setValue(value: T | T[] = this.selected) {
    if (value !== null && value !== undefined) {
      let val = _.isArray<T>(value) ? value.map(_ => this.getValue(_)) : this.getValue(value);
      if (!_.isEqual(val, this.dropdown.dropdown('get value')) || (_.isEmpty(val) ? !!this.dropdown.dropdown('get text') : !this.dropdown.dropdown('get text'))) {
        this.dropdown.dropdown('set selected', val);
        this.dropdown.find('select').val(val);
      }
    }
  }
}

// tslint:disable:component-selector no-forward-ref use-input-property-decorator use-output-property-decorator
@Component({
  selector: 'select[selector=project]',
  providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ProjectSelectorComponent), multi: true }],
  inputs: ['options', 'selected', 'settings'],
  outputs: ['select'],
  template: `
    <option *ngFor="let option of options" value="{{ option._id }}">{{ option.name }}</option>
  `
})
// tslint:enable
export class ProjectSelectorComponent extends SelectorComponent<string> implements OnInit {
  options: Mongo.Cursor<Project>;

  constructor(element: ElementRef) {
    super(element);
  }

  ngOnInit() {
    this.options = this.options || Projects.find();
  }
}

Downgrading back to meteor 1.4.X seems to "fix" the problem. I also upgraded typescript to 2.3.2, and attempted to install the node tslib package.

A screenshot of the javascript is attached.

Any thoughts on how to debug this cryptic error?

screen shot 2017-07-07 at 5 10 36 pm

My tsconfig.json (I tried adding the importHelpers compiler option, didn't work either):

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "*": [
        "*"
      ]
    },
    "target": "es5",
    "lib": [
      "dom",
      "es5",
      "scripthost"
    ],
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": true,
    "newLine": "LF",
    "sourceMap": true,
    "noUnusedLocals": true,
    "pretty": true,
    "importHelpers": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "exclude": [
    ".meteor",
    ".dist",
    "node_modules",
    "packages",
    "typings/custom",
    "typings/globals",
    "typings/modules"
  ]
}

When I revert back to meteor 1.4.4.2, with everything "working", this is what the generated javascript in the barbatus:typescript-runtime lib looks like:

(function (exporter) {                                                                                                 // 45
    __extends = function (d, b) {                                                                                      // 46
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];                                                         // 47
        function __() { this.constructor = d; }                                                                        // 48
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());                          // 49
    };                                                                                                                 // 50
                                                                                                                       // 51
    __assign = Object.assign || function (t) {                                                                         // 52
        for (var s, i = 1, n = arguments.length; i < n; i++) {                                                         // 53
            s = arguments[i];                                                                                          // 54
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];                              // 55
        }                                                                                                              // 56
        return t;                                                                                                      // 57
    };                                                                                                                 // 58
                                                                                                                       // 59
    __decorate = function (decorators, target, key, desc) {                                                            // 60
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;                                                 // 64
    };                                                                                                                 // 65
                                                                                                                       // 66
    __param = function (paramIndex, decorator) {                                                                       // 67
        return function (target, key) { decorator(target, key, paramIndex); }                                          // 68
    };                                                                                                                 // 69
                                                                                                                       // 70
    __metadata = function (metadataKey, metadataValue) {                                                               // 71
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
    };                                                                                                                 // 73
                                                                                                                       // 74
    __awaiter = function (thisArg, _arguments, P, generator) {                                                         // 75
        return new (P || (P = Promise))(function (resolve, reject) {                                                   // 76
            function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }                // 77
            function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }             // 78
            function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments)).next());                                           // 80
        });                                                                                                            // 81
    };                                                                                                                 // 82
                                                                                                                       // 83
    __generator = function (thisArg, body) {                                                                           // 84
        var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t;
        return { next: verb(0), "throw": verb(1), "return": verb(2) };                                                 // 86
        function verb(n) { return function (v) { return step([n, v]); }; }                                             // 87
        function step(op) {                                                                                            // 88
            if (f) throw new TypeError("Generator is already executing.");                                             // 89
            while (_) try {                                                                                            // 90
                if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
                if (y = 0, t) op = [0, t.value];                                                                       // 92
                switch (op[0]) {                                                                                       // 93
                    case 0: case 1: t = op; break;                                                                     // 94
                    case 4: _.label++; return { value: op[1], done: false };                                           // 95
                    case 5: _.label++; y = op[1]; op = [0]; continue;                                                  // 96
                    case 7: op = _.ops.pop(); _.trys.pop(); continue;                                                  // 97
                    default:                                                                                           // 98
                        if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                        if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }         // 100
                        if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }                          // 101
                        if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }                            // 102
                        if (t[2]) _.ops.pop();                                                                         // 103
                        _.trys.pop(); continue;                                                                        // 104
                }                                                                                                      // 105
                op = body.call(thisArg, _);                                                                            // 106
            } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }                                                 // 107
            if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };                          // 108
        }                                                                                                              // 109
    };                                                                                                                 // 110
                                                                                                                       // 111
    exporter("__extends", __extends);                                                                                  // 112
    exporter("__assign", __assign);                                                                                    // 113
    exporter("__decorate", __decorate);                                                                                // 114
    exporter("__param", __param);                                                                                      // 115
    exporter("__metadata", __metadata);                                                                                // 116
    exporter("__awaiter", __awaiter);                                                                                  // 117
    exporter("__generator", __generator);                                                                              // 118
});                                           

A little more details: I can get Meteor 1.5 to work if I lock specific versions down of the following packages:

barbatus:typescript@0.6.5_1
barbatus:typescript-compiler@0.9.5
barbatus:typescript-runtime@1.0.0

mctep commented

I have the same problem.
Possible it depends on microsoft/TypeScript#16506

mctep commented

@denodaeus Try to as temporary fix:

@Component({ /*...*/ })
class ProjectSelectorComponent2 { /*...*/ }
export const ProjectSelectorComponent = ProjectSelectorComponent2;

upgraded to 0.6.8 and pls check if i's fixed

mctep commented

The original issue has left.

But I have many compilation errors about impossibility to find some modules and typings.

It looks like compiler includes typings from @types directory only and does not include modules typings and compilerOptions.types from my tsconfig.json.

UPD: It does not read typings section in module's package.json. If module have index.d.ts in root dir it works.

mctep commented

I think this issue could be closed.
I've created issue for module resolution barbatus/meteor-typescript#9