0

I have been using requirejs on couple projects, and today is the first time I got this problem and not sure how to fix it. I am using requirejs and tyepscript, I can't really tell what's wrong here. Can someone take a look?

Here is my main.ts:

///<reference path="../lib/require/requirejs.d.ts"/>
///<reference path="TestClass.ts"/>
require.config(
    {
        baseUrl: 'js',
        paths: {
            puremvc: 'lib/puremvc/puremvc_standard_1.0_min'
        }
    }
);
require(
    [
        'puremvc',
        'sim/TestClass'
    ],
    function (TestClass ) {
        var test = new TestClass();
        test.logMsg("WHO AM I");
    }
);

and this is my TestClass.ts

class TestClass{
    constructor(){
        console.log ("TestClass constructor")
    }
   public logMsg(msg:string){
        console.log ("TestClass.log(): " + msg);
    }
}
export = TestClass;

and my sim.html looks like this one

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Simulation Tester</title>
<script src="js/lib/puremvc/puremvc_standard_1.0_min.js"></script>
<script data-main="js/sim/main.js" src="js/lib/require/require.js" ></script>
</head>
<body >
</body>
</html>

And this is my folder structure:

- root 
    - sim.html
    - js
        - lib
            - require (containt requirejs)
        - sim
            - main.ts
            - TestClass.ts

Any idea?

1 Answer 1

1

Are you loading puremvc through the script tag, or through require.js? I don't think you want to do both.

Over here:

require(
    [
        'puremvc',
        'sim/TestClass'
    ],
    function (TestClass ) {
        var test = new TestClass();
        test.logMsg("WHO AM I");
    }
);

The callback function gets the modules in the same order you listed them. So the 'TestClass' parameter is being supplied the value from the 'puremvc' module. You probably want function(puremvc, TestClass) instead here.

Sign up to request clarification or add additional context in comments.

1 Comment

That's it. I remove puremvc script tag from HTML and change the function(TestClass) to function (puremvc, TestClass) Thank you so much. I guess I've been doing it all wrong a while but now today is the first time I got this error. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.