TypeError: require.config is not a function

隐身守侯 提交于 2020-08-01 16:38:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20876136/typeerror-require-config-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!