Meteor ReferenceError:升级到1.3后未定义集合

时间:2016-01-30 11:34:19

标签: meteor

将Meteor版本从1.2升级到1.3后我收到此错误:

=> Started proxy.
=> Started MongoDB.
W20160130-14:27:48.841(3)? (STDERR)
W20160130-14:27:48.841(3)? (STDERR) C:\Users\Vladimir\AppData\Local\.meteor\pack
ages\meteor-tool\1.1.12-modules.5\mt-os.windows.x86_32\dev_bundle\server-lib\nod
e_modules\fibers\future.js:245
W20160130-14:27:48.841(3)? (STDERR)
throw(ex);
W20160130-14:27:48.841(3)? (STDERR)
      ^
W20160130-14:27:48.841(3)? (STDERR) ReferenceError: Games is not defined
W20160130-14:27:48.841(3)? (STDERR)     at meteorInstall.lib.collections.js (lib
/collections.js:1:1)
W20160130-14:27:48.841(3)? (STDERR)     at fileEvaluate (packages/modules-runtim
e/.npm/package/node_modules/install/install.js:183:1)
W20160130-14:27:48.841(3)? (STDERR)     at require (packages/modules-runtime/.np
m/package/node_modules/install/install.js:75:1)
W20160130-14:27:48.841(3)? (STDERR)     at C:\code\steambot\.meteor\local\build\
programs\server\app\app.js:404:1
W20160130-14:27:48.841(3)? (STDERR)     at C:\code\steambot\.meteor\local\build\
programs\server\boot.js:242:10
W20160130-14:27:48.841(3)? (STDERR)     at Array.forEach (native)
W20160130-14:27:48.841(3)? (STDERR)     at Function._.each._.forEach (C:\Users\V
ladimir\AppData\Local\.meteor\packages\meteor-tool\1.1.12-modules.5\mt-os.window
s.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
W20160130-14:27:48.841(3)? (STDERR)     at C:\code\steambot\.meteor\local\build\
programs\server\boot.js:137:5
=> Exited with code: 8

我的文件结构:

-.meteor
-client
-server
-public
-lib (collections.js here)

collections.js:

Games = new Mongo.Collection('games');

在升级到1.3之前,一切正常。

2 个答案:

答案 0 :(得分:4)

在Meteor 1.3推荐的方式中,使用import而不是将所有内容都移动到全局。

// collections.js
export const Games = new Mongo.Collection('games');

然后

// any_other_file.js
import { Games } from '../lib/collections'

答案 1 :(得分:2)

而不是

Games = new Mongo.Collection('games');

DO

global.Games = new Mongo.Collection('games');

becouse

  

在测试版5中,全局变量存在问题。

更多信息:https://github.com/meteor/meteor/issues/5788#issuecomment-175927524