0

I have little hierarchy of ts classes and enums:
Entities/enums/CardClassification.ts

export enum CardClassification {
   None,
   Domestic,
   // Other one
}

Entities/enums/CardState.ts

export enum CardState {
    InProgress = 1,
    Finished = 2,
    Canceled = 4
}

Entities/enums/CardTimeType.ts

export enum CardTimeType {
    XTimesPerPeriod = 1,
    XMinutesPerPeriod = 2,
}

Entities/Card.ts

import { CardState } from "./enums/CardState";
import { CardTimeType } from "./enums/CardTimeType";
import { CardClassification } from "./enums/CardClassification";

export class Card {
    public State: CardState;
    public TimeType: CardTimeType;
    public Classification: CardClassification;
}

And I have some typescript to work with this entities: card-controller.ts

/// <reference path="../typings/jquery/jquery.d.ts" />
/// <reference path="../typings/bootstrap/index.d.ts" />

import { Card } from "../entities/Card";
import { CardClassification } from "../entities/enums/CardClassification";

$(() => {
    // Do some work here
})

I use AMD module system and 6 ECMAscript version. Also I added require.js. In time of web page loading I've recivied 2 errors: For Card.ts:

Uncaught Error: Mismatched anonymous define() module: function (require, exports) {
    "use strict";
    class Card {
    }
    exports.Card = Card;
}
http://requirejs.org/docs/errors.html#mismatch
    at makeError (require.js:168)
    at intakeDefines (require.js:1254)
    at require.js:1452

And the same for CardClassification.ts:

Uncaught Error: Mismatched anonymous define() module: function (require, exports) {
    "use strict";
    var CardClassification;
    (function (CardClassification) {
        CardClassification[CardClassification["None"] = 0] = "None";
        CardClassification[CardClassification["Domestic"] = 1] = "Domestic";
    })(CardClassification = exports.CardClassification || (exports.CardClassification = {}));
}
http://requirejs.org/docs/errors.html#mismatch
    at makeError (require.js:168)
    at intakeDefines (require.js:1254)
    at require.js:1452

Also I've check generated .js files and really some mess here, look: 1) card-controller.js

/// <reference path="../typings/jquery/jquery.d.ts" />
/// <reference path="../typings/bootstrap/index.d.ts" />
define(["require", "exports", "../entities/enums/CardClassification" <-- What is here!?], function (require, exports, CardClassification_1) {
    "use strict";
    $(() => {
        // Do some stuff
        });
    });
});
//# sourceMappingURL=card-controller.js.map

Look at the "../entities/enums/CardClassification" string. I'm noobie with TypeScript, JS, RequireJS and all this stuff. Should it be here?

2) card.js

define(["require", "exports"], function (require, exports) {
    "use strict";
    class Card {
    }
    exports.Card = Card;
});
//# sourceMappingURL=Card.js.map

card.js in is empty! There is no any output js here. What's wrong with this stuff?

Update
tsconfig.json:

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es6",
    "module": "amd"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}
  • Can you add you bootstrapping code (where you load RequireJS and your app in html)? Also add your tsconfig.json and typescript version please. – Aluan Haddad Mar 11 '17 at 13:30
  • BTW empty card class is correct since you are not initializing the properties there is no emit for them. Your class code is correct and so is emit so nothing to worry about there. – Aluan Haddad Mar 11 '17 at 13:33
  • There are only a few proximate causes for "Mismatched anonymous define". They are all listed in the question against which yours was closed as duplicate. – Louis Mar 11 '17 at 13:36
  • @Louis, but the problem is not "Why can receive require.js error?". I assume that I receive is because of strange generated files. I question why I've get such generation output which lead me to require.js error. – Rustam Salakhutdinov Mar 11 '17 at 13:39
  • 1
    For readers to ascertain that what you claim here is indeed true (i.e. that there's some mysterious configuration that leads to the error), you need to transform your question into a [mcve]. Your question is not a [mcve]. It lacks critical information that Aluan Haddad has requested already ("your bootstrapping code") and is more complicated than necessary: a couple of non-project-specific modules should do it. You don't have to show 5 modules like you do now. That's just noise that readers must wade through to get to the real problem. – Louis Mar 11 '17 at 13:44

0 Answers0