2012-05-31 38 views
8

http://requirejs.org/RequireJS插件(order.js)

我最近下載require.js 2.0,我在我的控制檯收到錯誤:

Uncaught TypeError: Object function(){var g=ga.call(arguments,0),e;if(f&&v(e=g[g.length-1]))e.__requireJsBuild=!0;g.push(d);return b.apply(null,g)} has no method 'nameToUrl' 

是order.js插件仍然requirejs支持?我沒有在網站上看到它的文檔。

當我嘗試刪除文件腳本中斷。

在我的索引文件,我包括在頭部分requirejs腳本:

<!DOCTYPE html> 
<html> 
    <head> 
     <title> 
      My Mobile Application 
     </title> 
     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" /> 
     <link rel="stylesheet" href="public/css/style.css" /> 
     <script data-main="scripts/main.js" src="scripts/require.js"></script> 
    </head> 
    <body></body> 
</html> 

然後在我main.js文件:

requirejs.config({ 
    //By default load any module IDs from js/lib 
    baseUrl: 'js/lib', 
    //except, if the module ID starts with "app", 
    //load it from the js/app directory. paths 
    //config is relative to the baseUrl, and 
    //never includes a ".js" extension since 
    //the paths config could be for a directory. 
    paths: { 
     app: '../app', 
     assets: '../assets', 
     views: '../app/views', 
     templates: '../app/templates', 
     collections: '../app/collections', 
     models: '../app/models' 
    } 
}); 

// Start the main app logic. 
requirejs([ 
    'jquery/jquery', 
    'assets/jqm.config', 
    'jquery/mobile', 
    'text' 
]); 

require([ 
    'app' 
    ], 
    function(App){ 
     $(document).ready(function(){ 
      App.initialize(); 
     }); 
    } 
); 

我看到它,App.initialize沒有按」沒有任何錯誤,而App.initialize正在做的只是簡單的地理位置。 requirejs只是要求order.js,當我把代碼與上面提到的相同的錯誤。

謝謝!

+3

[Stack Overflow不是心靈讀者](http://meta.stackexchange.com/a/128551/177538)。代碼是什麼? – Joseph

+1

對不起。編輯。 :) –

回答

17

您認爲order不再被支持是正確的。它有利於shim配置選項中移除:

So, the the order plugin has been removed and following the lead of Tim Branyen and Dave Geddes, of use and wrap respectively, requirejs 2.0 integrates that kind of dependency tree specification directly in requirejs.

需要2.0升級說明 - https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0

同時,檢查的RequireJS網站shim文檔 - http://requirejs.org/docs/api.html#config-shim

+0

好的,非常感謝,這確實是一個很大的幫助。將現在嘗試它,讓你知道它是否正在工作:) –

+0

我正在使用jQuery的方式和更早的時候我下載了[鏈接](http://requirejs.org/docs/download.html#samplejquery)文件從給定的鏈接,我用它的要求-jquery.js而不是require.js,現在我收到這個錯誤:插件是未定義的。它很難調試種類錯誤。 –

+0

在chrome的檢查元素中,我收到此錯誤:無法讀取未定義的屬性'normalize'。嘆息* –

2

哦了它。

//This is our main applicatoon boot loader or bootstrap 
//here we are loading necessary scripts dependencies like 
//jquery, jqm.config, mobile, text 


requirejs.config({ 
    baseUrl: 'js/libs', 
    //except, if the module ID starts with "app", 
    //load it from the js/app directory. paths 
    //config is relative to the baseUrl, and 
    //never includes a ".js" extension since 
    //the paths config could be for a directory. 
    paths: { 
     app: '../app', 
     assets: '../assets', 
     views: '../app/views', 
     templates: '../app/templates', 
     collections: '../app/collections', 
     models: '../app/models' 
    } 
}); 

// Start the main app logic. 

require(["jquery","assets/jqm.config","jquery/mobile","text","app"], 
    function(
    $, 
    config, 
    mobile, 
    text, 
    App 
    ) { 
    //the jquery.alpha.js and jquery.beta.js plugins have been loaded. 
    $(function() { 
     App.initialize(); 
    }); 
});