javascript 类型错误:require.config 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20876136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: require.config is not a function
提问by bernie2436
I am using require.js as part of a brunch project. This code is throwing the error:
我正在使用 require.js 作为早午餐项目的一部分。此代码抛出错误:
;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?
这是否意味着 requirejs 没有正确包含在项目中?
回答by Louis
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 namedrequirejs
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 afterRequireJS is loaded. If it has aconfig
method defined at that point, then something else must be messing with it later.
RequireJS 未加载。
这可以通过打开浏览器的调试器查看网络请求并查看定义的文件是否
require
被浏览器询问并检查响应是否表明数据可用(即从服务器加载,从缓存加载)来诊断。RequireJS 已加载但未正确初始化。
如果某些东西在 RequireJS 之前加载并且以某种方式使 JavaScript 运行时混乱,从而导致 RequireJS 无法初始化,则可能会发生这种情况。例如,如果有东西在全局空间中放置了一个
define
任何类型的全局命名,或者全局命名requirejs
并且它是一个函数,那么 RequireJS 将默默地放弃初始化。我会用包含 RequireJS 的文件中的断点来诊断这个问题,以查看它是否完成执行。
RequireJS 已加载,但其他内容重新定义
require
。我会
require
在RequireJS 加载后检查 的值。如果它config
在那个时候定义了一个方法,那么以后一定有其他东西弄乱了它。