【问题标题】:require js paths not being recognised要求 js 路径不被识别
【发布时间】:2012-06-28 13:58:31
【问题描述】:

我正在使用 RequireJS 2.0.2

我在用作入口点的文件中有以下内容。

require({

    "packages"  : ['bi/charts'],
    baseurl     : '/js/',
    paths       : {
        handlebars  : "lib/handlebars-1.0.0.beta.6",
        jquery      : "lib/jquery-1.7.2.min",
        underscore  : "lib/underscore-1.3.3.min",
        modernizr   : "lib/modernizr-custom.2.5.3.min",
        BI          : "bi/BIf"
    }
});

但是它只识别 'jquery' 而没有识别其他路径,它返回以下错误:

NetworkError: 404 Not Found - [link]http://localhost:62033/js/handlebars.js"
handlebars.js
Script error http://requirejs.org/docs/errors.html#scripterror
[Break On This Error]   

var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);

....想法?

非常感谢。

【问题讨论】:

    标签: javascript requirejs amd


    【解决方案1】:

    您可能需要在要求之前调用配置。还要注意在路径中添加斜线。使用:

    "handlebars" : "/lib/handlebars"
    

    不是

    "handlebars" : "lib/handlebars"
    
    
      require.config({
        baseUrl: "/js/",
        paths: {
            "handlebars": "/lib/handlebars"
        },
      });
      require( ["handlebars"],
        function(handlebars, myModule) {
        }
      );
    

    另见Config Paths

    【讨论】:

    • 想通了。因为我在页面中进行了多次要求调用,因为它正在构建包含 require.config 调用的 main.js 文件没有机会加载,因为首先执行了 require() 调用。必须将 require.config 调用放在页面中,而不是从 main.js 调用。
    • 然后自己创建一个答案并将其标记为已解决,以便看起来已回答。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-03
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 2012-09-21
    相关资源
    最近更新 更多