1

当我将 Mousetrap javascript 文件 (http://craig.is/killing/mice) 放在 Meteor 应用程序的主目录中时,出现以下错误:

Your app is crashing. Here's the latest log.

app/mousetrap.js:711
    _addEvent(document, 'keypress', _handleKey);
              ^
ReferenceError: document is not defined
    at app/mousetrap.js:711:15
    at app/mousetrap.js:813:4
    at /Users/Suchow/Desktop/Collective/.meteor/local/build/server/server.js:107:21
    at Array.forEach (native)
    at Function._.each._.forEach (/Users/Suchow/Desktop/Collective/.meteor/local/build/server/underscore.js:76:11)
    at run (/Users/Suchow/Desktop/Collective/.meteor/local/build/server/server.js:93:7)
Exited with code: 1
Your application is crashing. Waiting for file change.

当 Mousetrap 文件放置在 client/ 子目录中时,该错误消失。为什么?

4

2 回答 2

2

因为服务器端没有dom。如果你把它放在根目录下,它已经在服务器端和客户端加载。

lib 像 Sugarjs,momentjs 可以同时工作。

于 2012-11-12T02:20:21.607 回答
1

在 Meteor 1.0 中,创建包时,强制 Meteor 仅在客户端加载 3rd 方库的方法是显式将client参数传递到api.addFiles文件package.js

Package.onUse(function(api) {
    api.addFiles('lib/thirdpartylibrary.js', 'client');
}
于 2015-01-14T16:41:51.617 回答