De Char
De Char

Reputation: 73

Uncaught ReferenceError: require is not defined, I am using dojo1.7.2

I am using dojo1.7.2 I got firebug error: Uncaught ReferenceError: require is not defined

Here is my piece of code:

<script type="text/javascript" src="../js/release/dojo/dojo.js" 
 data-dojo-config="packages:[ {'name':'com','location':'/myApp/js/com'}], async: false, parseOnLoad: true, isDebug: true">
</script>
<script language="JavaScript" type="text/javascript">
    require(['dojo/dojo', "dijit/dijit", "dojox/dojox"], function () {
    require(["dojox/mobile", "dojo/parser"], function(mobile, parser){
        })
    });
</script>

Where did I wrong here? Thank in advance.

Upvotes: 4

Views: 12756

Answers (4)

jwallet
jwallet

Reputation: 328

We got that same issue at work, just to let other people know that if you got that error

Uncaught ReferenceError:require is not defined                at dojo.js:29
dojo.js:29

and you are using single-spa or importing a fixed version of SystemJS, like so <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.21.5/system-production.js"></script> that may be the cause. So having the production build was throwing this exception in development in our case, this was use for {mountParcel} with single-spa.

You can specify a non-production ready systemjs from index.html or use a better approach to don't have a that inject systemjs in your html.

Upvotes: 0

user3571799
user3571799

Reputation: 1

Initially you need to check for the dojo.js file where it is located. the ultimate thing you need to focus is where is your dojo folders are located and what is the location given at src tag ""

Upvotes: 0

Jess
Jess

Reputation: 25029

I just solved this problem. It is very very possible that my solution will not help since this problem can be caused by a lot of different things. I have my web site being served off of server1.blah.com and dojo is being served off of server2.blah.com. Normally the site is working fine. Then we got a new user and the site was not working well at all. I got the error in the web console:

ReferenceError: require is not defined

The problem was that both servers are using https, but there is no certificate. (This is an intranet application). So when you go to server1.blah.com it will ask you if you want to continue and add an exception. BUT! There is no exception for server2! So I had my new user navigate to server2.blah.com/blah/dojo.js and add the exception there. Now everything works! (Think about it. require in this case is coming from dojo. If you can't load dojo due to many possible reasons, the require function will not be defined)

Also, I'm not advocating this as a best practice by any means. Just set up your certificates!

Upvotes: 1

zclark
zclark

Reputation: 813

Could be an error loading dojo from the src you specified, as I don't know the folder structure, I can't tell.

<script language="JavaScript" type="text/javascript">
    require(["dojox/mobile", "dojo/parser"], function(mobile, parser){
        alert("hi");
    });
</script>

Here's a fiddle of it working http://jsfiddle.net/P4bvs/1/

This outer require ( require(['dojo/dojo', "dijit/dijit", "dojox/dojox"] ) is not required , though not what is causing your error.

Upvotes: 1

Related Questions