I have 2 files in TypeScript (I´ll create several more later), and I want to generate a unique JS file that other will use as a library.
At this moment, with the simplest exercise that join both files and loading them in a HTML file with SystemJS, I´m getting this error:
Error: (SystemJS) Multiple anonymous defines in module
I´m using TypeScript v1.8 and SystemJS v0.19.38. I have these 2 files:
Utils.ts
export const ValidatorRegExpEmail = /^([_A-Za-z0-9-+]+(\.[_A-Za-z0-9-]+)*)+@([A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,}))$/; // Christian
export class Validator {
static isEmail ( s: string ) {
return ValidatorRegExpEmail.test ( s.trim () );
}
}
Main.ts
import { Validator } from "./Utils";
console.log ( Validator.isEmail ( "email@server.com" ) ) ;
tsconfig.json
{
"compilerOptions": {
"module": "amd"
,"target": "es5"
,"sourceMap": true
},
"files": [
"src/Utils.ts"
,"src/Main.ts"
]
}
I´m using gulp-typescript to compile and generate a unique JS file. And generate this file:
Main.js
define(["require", "exports"], function (require, exports) {
"use strict";
exports.ValidatorRegExpEmail = /^([_A-Za-z0-9-+]+(\.[_A-Za-z0-9-]+)*)+@([A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,}))$/; // Christian
var Validator = (function () {
function Validator() {
}
Validator.isEmail = function (s) {
return exports.ValidatorRegExpEmail.test(s.trim());
};
return Validator;
}());
exports.Validator = Validator;
});
define(["require", "exports", "./Utils"], function (require, exports, Utils_1) {
"use strict";
console.log(Utils_1.Validator.isEmail("ghporras@gmail.com"));
});
Finally, in my HTML I have this loading:
<head>
<script src="MyLibv1.0/vendor/system.js"></script>
<script>
System.config({
baseURL: "MyLibv1.0/"
});
System.defaultJSExtensions = true;
System.import("Main").catch(function(e)
{
console.error(e);
});
</script>
...
Loading this html in Chrome I´m getting this error:
Error: (SystemJS) Multiple anonymous defines in module
If I change in tsconfig.json from
"module": "amd"
to:
"module": "system"
Then in Chrome I´m getting this error:
Error: (SystemJS) Multiple anonymous System.register
If loading a bundle, ensure all the System.register calls are named.
Why? What I´m doing wrong?