将 Meteor 版本从 1.2 升级到 1.3 后,我收到此错误:
=> Started proxy.
=> Started MongoDB.
W20160130-14:27:48.841(3)? (STDERR)
W20160130-14:27:48.841(3)? (STDERR) C:UsersVladimirAppDataLocal.meteorpack
agesmeteor-tool1.1.12-modules.5mt-os.windows.x86_32dev_bundleserver-libnod
e_modulesfibersfuture.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:codesteambot.meteorlocalbuild
programsserverappapp.js:404:1
W20160130-14:27:48.841(3)? (STDERR) at C:codesteambot.meteorlocalbuild
programsserverboot.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:UsersV
ladimirAppDataLocal.meteorpackagesmeteor-tool1.1.12-modules.5mt-os.window
s.x86_32dev_bundleserver-libnode_modulesunderscoreunderscore.js:79:11)
W20160130-14:27:48.841(3)? (STDERR) at C:codesteambot.meteorlocalbuild
programsserverboot.js:137:5
=> Exited with code: 8
我的文件结构:
-.meteor
-client
-server
-public
-lib (collections.js here)
收藏.js:
Games = new Mongo.Collection('games');
在升级到1.3之前,一切正常。
在 Meteor 1.3 中,推荐的方法是使用 import
而不是将所有内容移动到全局中。
// collections.js
export const Games = new Mongo.Collection('games');
然后
// any_other_file.js
import { Games } from '../lib/collections'
而不是
Games = new Mongo.Collection('games');
做
global.Games = new Mongo.Collection('games');
贝库斯
在beta 5中,全局变量遇到了问题。
更多信息: https://github.com/meteor/meteor/issues/5788#issuecomment-175927524