1

我正在尝试使用 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.

我想我应该以某种方式告诉编译器源应该从网络浏览器运行(只是猜测)......

4

2 回答 2

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'],

这似乎对我有用。

于 2014-01-08T10:00:04.950 回答
0

我遇到了同样的问题。只需删除组件中的 jquery 依赖项,它应该可以解决它。

就像是 define(['jquery'], function GoogleMapsLoader($) {

应该替换为

define(function GoogleMapsLoader() {

阅读本文应该对您有所帮助。

于 2015-09-20T23:58:52.857 回答