TypeError: require.config is not a function

brunch, javascript, node.js, requirejs

Solution

If you get that error, it could be that:

RequireJS is not loaded.

This can diagnosed by opening the browser's debugger to look at network requests and seeing whether the file that defines `require` is asked by the browser and checking that the response indicates that the data is available (i.e. loaded from the server, loaded from cache).

RequireJS is loaded but not initializing properly.

This could happen if something is loaded before RequireJS and somehow messes with the JavaScript runtime in a way that makes RequireJS fail to initialize. For instance, if something puts in the global space a global named `define` of any type, or global named `requirejs` and which is a function, then RequireJS will silently abandon initializing.

I'd diagnose this with breakpoints in the file that contains RequireJS to see whether it completes execution or not.

RequireJS is loaded but something else redefines `require`.

I'd inspect the value of `require` just after RequireJS is loaded. If it has a `config` method defined at that point, then something else must be messing with it later.

Problem

I am using require.js as part of a brunch project. This code is throwing the error: ``` ;require.config({ // require.config is not a function paths: { jquery: "lib/jquery", underscore: "lib/underscore", backbone: "lib/backbone", localstorage: "lib/backbone.localStorage" } }); ``` Does that mean that requirejs is not getting included properly in the project?

Original source