2017-03-29 17 views
0

我想在我的代碼中使用r.js使用jQuery 。但是在評估jQuery時失敗了。r.js導致:評估./lib/jquery.js作爲模塊「jquery」失敗,出現錯誤:TypeError:無法讀取未定義的屬性'createElement'

這是錯誤消息我得到:我搜索了的jquery.js 「的createElement」

$ r.js init-edx-machine.js /usr/local/lib/node_modules/requirejs/bin/r.js:393 throw err; ^

Error: Evaluating ./lib/jquery.js as module "jquery" failed with error: TypeError: Cannot read property 'createElement' of undefined at Function.req.load (/usr/local/lib/node_modules/requirejs/bin/r.js:2571:23) at Object.load (/usr/local/lib/node_modules/requirejs/bin/r.js:1935:21) at Module.load (/usr/local/lib/node_modules/requirejs/bin/r.js:1084:29) at Module.fetch (/usr/local/lib/node_modules/requirejs/bin/r.js:1074:66) at Module.check (/usr/local/lib/node_modules/requirejs/bin/r.js:1106:30) at Module.enable (/usr/local/lib/node_modules/requirejs/bin/r.js:1426:22) at Object.enable (/usr/local/lib/node_modules/requirejs/bin/r.js:1807:39) at Module. (/usr/local/lib/node_modules/requirejs/bin/r.js:1411:33) at /usr/local/lib/node_modules/requirejs/bin/r.js:384:23 at each (/usr/local/lib/node_modules/requirejs/bin/r.js:309:31)

。大多數情況下它使用文檔。有時它使用通過參數給出的變量。

jQuery版本是2.1.4。我檢查了更新的版本,他們這樣做。

我真的不知道這裏發生了什麼。我現在能做什麼?

回答

2

使用r.js沒有選項會使它想要執行你的代碼,這是在這裏發生的。由於Node.js中沒有document默認全局可用(與瀏覽器相反),因此代碼失敗,因此可能會出現錯誤。

要進行優化,你需要通過-o說法:r.js -o ...

+0

哦,該死......我錯過了這一點。我以爲「-o」定義了輸出文件。 – Ctwx

相關問題