简体   繁体   English

TypeError:require.config不是函数

[英]TypeError: require.config is not a function

I am using require.js as part of a brunch project. 我使用require.js作为早午餐项目的一部分。 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? 这是否意味着requirejs没有被正确地包含在项目中?

If you get that error, it could be that: 如果你得到那个错误,可能是这样的:

  • RequireJS is not loaded. RequireJS未加载。

    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 (ie loaded from the server, loaded from cache). 这可以通过打开浏览器的调试器来查看网络请求并查看是否由浏览器询问定义require的文件并检查响应是否表明数据可用(即从服务器加载,从缓存加载)来诊断。

  • RequireJS is loaded but not initializing properly. RequireJS已加载但未正确初始化。

    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. 如果在RequireJS之前加载某些东西并且以某种方式混淆JavaScript运行时会导致RequireJS无法初始化,则可能会发生这种情况。 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. 例如,如果某些东西在全局空间中放入任何类型的全局命名define ,或者全局命名为requirejs并且是一个函数,那么RequireJS将默默地放弃初始化。

    I'd diagnose this with breakpoints in the file that contains RequireJS to see whether it completes execution or not. 我在包含RequireJS的文件中使用断点来诊断它,以查看它是否完成执行。

  • RequireJS is loaded but something else redefines require . RequireJS已加载但require重新定义其他内容。

    I'd inspect the value of require just after RequireJS is loaded. 加载RequireJS 我会检查require的值。 If it has a config method defined at that point, then something else must be messing with it later. 如果它在那时定义了config方法,那么其他东西必须在以后搞乱它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM