我正在尝试使用requirejs优化器,但是我收到以下错误:
从节点运行:
$ node r.js js/main.js -o build.js
Error: Evaluating js/app/main.js as module "app/main" failed with error:
Error: Evaluating js/lib/jquery-1.8.0.js as module "jquery" failed
with error: ReferenceError: window is not defined
从java
运行$ java -classpath js/lib/dist/js.jar:js/lib/dist/compiler.jar org.mozilla.javascript.tools.shell.Main r.js js/main.js
js: uncaught JavaScript runtime exception: ReferenceError: "window" is not defined.
js: uncaught JavaScript runtime exception: ReferenceError: "window" is not defined.
js: uncaught JavaScript runtime exception: ReferenceError: "window" is not defined.
我想不知怎的,我应该告诉编译器这个源是从Web浏览器运行的(只是猜测)......
答案 0 :(得分:0)
我的配置文件设置如下:
require.config({
paths: {
jquery: 'lib/jquery',
backbone: 'lib/backbone',
backboneLocalStorage: 'lib/backbone.localStorage',
underscore: 'lib/underscore',
util: 'lib/util',
config: 'config',
lang: 'lang',
hammer: 'lib/hammer',
moment: 'lib/jquery_plugins/moment',
slider: 'lib/jquery_plugins/slider'
},
shim: {
jquery: {
exports: 'jquery'
},
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore'],
exports: 'Backbone'
},
hammer: {
deps: ['jquery'],
exports: 'Hammer'
},
slider: {
deps: ['jquery']
},
moment: {
deps: ['jquery']
}
}
});
我不得不改变
jquery: {
exports: 'jquery'
},
到
jquery: ['jquery'],
这似乎对我有用。
答案 1 :(得分:0)
我遇到了同样的问题。只需删除组件中的jquery依赖项,它就应该解决它。
喜欢的东西
define(['jquery'],
function GoogleMapsLoader($) {
应替换为
define(function GoogleMapsLoader() {
阅读this应该会对你有帮助。