当我第一次浏览我的webapp时(通常在缓存被禁用的浏览器中),我会遇到这个错误.

错误:不匹配的匿名定义()模块:函数(必需){

HTML:

<html>
   .
   .
   .
   <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
   <script> var require = { urlArgs: "v=0.4.1.32" }; </script>
   <script data-main="assets/js/main" src="assets/js/libs/require.js"></script>
   <script src="assets/js/ace/ace.js?v=0.4.1.32"></script>
   </body>
</html>

JS:

$(function () {
    define(function (require) {
        // do something
    });
});

Anyone know exactly what this error means and why its happening?

source file,github问题页面上的short discussion

推荐答案

就像AlienWebGuy说的,根据doctor 的说法,如果

  • 您在自己的script标记中有一个匿名定义("modules that call define() with no string ID")(我假设它们实际上指的是全局范围内的任何地方).
  • You have modules that have conflicting names
  • You use loader plugins or anonymous modules but don't use require.js's optimizer to bundle them

I had this problem while including bundles built with browserify alongside require.js modules. The solution was to either:

A. load the non-require.js standalone bundles in script tags before require.js is loaded, or

B. load them using require.js (instead of a script tag)

Jquery相关问答推荐

formData.append 来自不同输入文件的两个文件

从文本区域获取值

修改对象数组中的对象属性

为什么我的 toFixed() 函数不起作用?

使用 jQuery click 处理锚点 onClick()

JSON字符串到JS对象

jQuery JSON到字符串?

jQuery绑定到粘贴事件,如何获取粘贴的内容

JSON 到字符串变量转储

如何在 jQuery 中为 getJSON 设置缓存 false?

Onchange 通过 Select 打开 URL - jQuery

在 HTML 表单提交上制作 Enter 键而不是激活按钮

使用 jQuery 刷新(重新加载)页面一次?

根据弹出框相对于窗口边缘的 X 位置更改 Bootstrap 弹出框的位置?

从附加元素获取 jQuery 对象的更简单方法

所有选中复选框的 jQuery 数组(按类)

jQuery XML 错误请求的资源上不存在‘Access-Control-Allow-Origin’标头.

如何隐藏 Twitter Bootstrap 下拉菜单

用于发布和获取的 Ajax 教程

带有 LIKE 的 Spring JPA @Query