1

更新:问题不在火花中-尽管我误解了发生的事情,因此问题的形成有些不正确,但我将这个问题留了下来,以防万一它有利于其他人。

我收到以下错误:

Exception from Deps recompute: TypeError: Cannot read property 'nodeName' of null
at Patcher.match (http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:1540:12)

当我单击第二行的链接时,它会将我定向到 spark.js 的以下部分,其中错误是:

// Look at tags of parents until we hit parent of last-kept,                                   // 229
// which we know is ok.                                                                        // 230
for(var a=tgt.parentNode, b=src.parentNode;                                                    // 231
    a !== (starting ? this.tgtParent : lastKeptTgt.parentNode);                                // 232
    a = a.parentNode, b = b.parentNode) {                                                      // 233
  if (b === (starting ? this.srcParent : lastKeptSrc.parentNode))                              // 234
    return false; // src is shallower, b hit top first                                         // 235
  if (a.nodeName !== b.nodeName)                                                               // 236
    return false; // tag names don't match                                                     // 237
}          

违规行是这一行:if (a.nodeName !== b.nodeName)。我想调试这个...如何修改 spark.js 文件?我想在语句中输入 as console.log(a),并想检查是否a具有b该属性nodeName

StackOverflow 上与此相关的问题是:

如何调查“Exception form Deps recompute”有哪些线索?

如何修改正在运行的 Meteor(陨石)?

第一个没有真正回答。第二个包括有关如何将包添加到流星以便您可以修改它的建议。但这对我不起作用——我的修改要么没有出现(如果我遵循上面链接 #2 中的建议),要么生成了一个错误,说流星找不到 spark.js(如果我试图修改 spark我的项目的 ~/.meteor/ 或 .meteor/ 目录中的包文件夹的客户端文件夹中的 .js 文件。

有人对我如何修改我的流星项目的 spark.js 文件(客户端版本)有任何建议吗?

谢谢!

2013 年 11 月 9 日更新:

我收到这些错误的原因是因为我试图将异步调用谷歌地图 geocoder.geocode() 对象/方法的结果存储在反应会话变量中:

SessionAmplify = _.extend({}, Session, {
        keys: _.object(_.map(amplify.store(), function(value, key) {
        return [key, JSON.stringify(value)]
    })),
    set: function (key, value) {
        Session.set.apply(this, arguments);
        amplify.store(key, value);
    },
});

setLocation = function (e) {
    e.preventDefault;
    var address = e.target.value;
    geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {      
            map.setCenter(results[0].geometry.location);
            $('.found-address').html(results[0].formatted_address);

            SessionAmplify.set('pos', results[0].geometry.location);
            SessionAmplify.set('formatted_address', results[0].formatted_address);

        } else {
            alert('Geocode was not successful for the following reason: ' + status);
        }
    });
    return true;
};

问题线是SessionAmplify.set('pos', results[0].geometry.location);SessionAmplify.set('formatted_address', results[0].formatted_address);。似乎该results变量没有及时到达我设置会话变量 - 这很奇怪,因为除非变量到达,否则该代码块不应运行status,我认为变量应该与results变量同时到达。

我研究了使用Meteor._wrapAsync()(我观看了 eventedmind 教程:https ://www.eventedmind.com/feed/Ww3rQrHJo8FLgK7FF ),但我不知道如何Meteor._wrapAsync()使用geocoder.geocode(). 一个问题是Meteor._wrapAsync()要求回调函数具有表单函数(错误,结果),但地理编码回调的函数具有表单function(result, status)。有什么建议吗?

4

2 回答 2

3

好的,这不是 Spark 问题/异常。事实上,您的模板使用了一些未完全初始化的对象 var。这是一个非常常见的错误。因此,在您的模板 javascript 文件中,您必须注意这些对象,并且您不必忘记在使用它们之前检查它们是否可用:

if (_.contains(myObject, ['prop1', 'prop2])) {
    // your function template code here
}

流星应用程序的另一点:通常当您的应用程序加载到客户端时,您没有收到所有数据(每个示例都没有记录用户),但您的模板将被渲染一次。然后,通过您的订阅,客户将收到数据,并且您的模板将被重新呈现......

我希望它会帮助你。

[编辑] 这是一个带有请求的示例:

  // your npm async lib
  var stdRequest = Npm.require('request');
  // your anonymous func that wrap the async lib (you can do what you want here
  var requestGetAsync = function(url, options, cb) {
     stdRequest.get(url, options, function (err, response, body) {
        cb && cb(null, response);
     });
  };
  // the final wraping to make it sync
  requestGetSync = Meteor._wrapAsync(requestGetAsync);

如果您不想使用个人 ano func 自定义异步库,您可以这样做:

  // the only wraping required
  requestGetSync = Meteor._wrapAsync(request);

要使用它,您只需执行以下操作:

  requestGetSync(/* standard params of original func */);
于 2013-11-04T09:53:18.323 回答
0

该错误可能不在 Spark 中。当我在 Meteor 应用程序中添加新代码时,我经常会遇到类似的错误。因此,如果我在控制台中看到此错误,我会尝试注释新代码并找到有问题的行并尝试更改它。

于 2013-11-04T08:00:10.777 回答