Common Errors

This page lists errors that are generated by RequireJS. If the following information does not fix the problem, you can ask on the RequireJS list or open an issue. In either case it is best to have an example or detailed explanation of the problem, hopefully with steps to reproduce.

Mismatched anonymous define() modules ...§ 1

If you manually code a script tag in HTML to load a script with an anonymous define() call, this error can occur.

Also seen if you manually code a script tag in HTML to load a script that has a few named modules, but then try to load an anonymous module that ends up having the same name as one of the named modules in the script loaded by the manually coded script tag.

Finally, if you use the loader plugins or anonymous modules (modules that call define() with no string ID) but do not use the RequireJS optimizer to combine files together, this error can occur. The optimizer knows how to name anonymous modules correctly so that they can be combined with other modules in an optimized file.

To avoid the error:

Load timeout for modules: ...§ 2

Likely causes and fixes:

Error evaluating module ...§ 3

An error occured when the define() function was called for the module given in the error message. It is an error with the code logic inside the define function. The error could happen inside a require callback.

In Firefox and WebKit browsers, a line number and file name will be indicated in the error. It can be used to locate the source of the problem. Better isolation of the error can be done by using a debugger to place a breakpoint in the file that contains the error.

Module name ... has not been loaded yet for context: ...§ 4

This occurs when there is a require('name') call, but the 'name' module has not been loaded yet.

If the error message includes Use require([]), then it was a top-level require call (not a require call inside a define() call) that should be using the async, callback version of require to load the code:

//If this code is not in a define call,
//DO NOT use require('foo'), but use the async
//callback version:
require(['foo'], function (foo) {
    //foo is now loaded.
});

If you are using the simplified define wrapper, make sure you have require as the first argument to the definition function:

define(function (require) {
    var namedModule = require('name');
});

If you are listing dependencies in the dependency array, make sure that require and name are in the dependency array:

define(['require', 'name'], function (require) {
    var namedModule = require('name');
});

In particular, the following will not work:

//THIS WILL FAIL
define(['require'], function (require) {
    var namedModule = require('name');
});

This fails because requirejs needs to be sure to load and execute all dependencies before calling the factory function above. If a dependency array is given to define(), then requirejs assumes that all dependencies are listed in that array, and it will not scan the factory function for other dependencies. So, either do not pass in the dependency array, or if using the dependency array, list all the dependencies in it.

If part of a require() callback, all the dependencies need to be listed in the array:

require(['require', 'name'], function (require) {
    var namedModule = require('name');
});

Be sure that require('name') only occurs inside a define() definition function or a require() callback function, never in the global space by its own.

In the RequreJS 1.0.x releases, there is a bug with having a space between the require and parens in WebKit browsers when using the simplified CommonJS wrapping (no dependency array):

define(function (require) {
    //Notice the space between require and the arguments.
    var namedModule = require ('name');
});

The workaround is to just remove the space. This is fixed in the 2.0 code, and may be backported to the 1.0.x series if a 1.0.9 release is done.

Invalid require call§ 5

This occurs when there is a call like:

require('dependency', function (dependency) {});

Asynchronously loading dependencies should use an array to list the dependencies:

require(['dependency'], function (dependency) {});

No define call for ...§ 6

This occurs when enforceDefine is set to true, and a script that is loaded either:

Or, if the error shows up only in IE and not in other browsers (which may generate a Script error, the script probably:

Those IE behaviors result in IE's quirks in detecting script errors.

To fix it:

Script error§ 7

This occurs when the script.onerror function is triggered in a browser. This usually means there is a JavaScript syntax error or other execution problem running the script. To fix it, examine the script that generated the error in a script debugger.

This error may not show up in IE, just other browsers, and instead, in IE you may see the No define call for ... error when you see "Script error". This is due to IE's quirks in detecting script errors.

No matching script interactive for ...§ 8

This error only shows up in some IE browsers. Most likely caused by loading a script that calls define() but was loaded in a plain script tag or via some other call, like an eval() of a JavaScript string.

To avoid the error, be sure to load all scripts that call define via the RequireJS API.

Path is not supported: ...§ 9

This error occurs when the optimizer encounters a path to a module or script which is a network path. The optimizer only allows building with local resources. To fix it:

Make sure you reference the network dependency as a module name, not as a full URL, so that it can be mapped to a different during the build:

//DO NOT DO THIS
require(['http://some.domain.dom/path/to/dependency.js'],
function (dependency) {});

//Rather, do this:
require.config({
    paths: {
        'dependency': 'http://some.domain.dom/path/to/dependency'
    }
});

require(['dependency'], function (dependency) {});

If you want to include this dependency in the built/optimized file, download the JS file and in the build profile for the optimizer, put in a paths config that points to that local file.

If you want to exclude that file from being included, and just need to map "dependency" for the build (otherwise it will not build), then use the special "empty:" paths config:

//Inside the build profile
{
    paths: {
        'dependency': 'empty:'
    }
}

Cannot use preserveLicenseComments and generateSourceMaps together§ 10

In the r.js optimizer, preserveLicenseComments works as a pre- and post-processing step on a JS file. Various kinds of license comments are found, pulled out of the JS source, then that modified source is passed to the minifier. When the minifier is done, the comments are added to the top of the file by the r.js optimizer.

However, for the minifier to accurately construct a source map, the minified source cannot be modified in any way, so preserveLicenseComments is incompatible with generateSourceMaps. generateSourceMaps was introduced in version 2.1.2 of the optimizer.

The default for the optimizer is for preserveLicenseComments to be true. So if using generateSourceMaps, then explicitly set preserveLicenseComments to false. If you want to preserve some license comments, you can manually modify the license comments in the JS source to use the JSDoc-style @license comment. See "Annotating JavaScript for the Closure Compiler" for more information. That same format works for UglifyJS2.

importScripts failed for ...§ 11

When RequireJS is used in a Web Worker, importScripts is used to load modules. If that call failed for some reason, this error is generated.