13

当我运行我的流星项目时,出现了这个问题:

ReferenceError: Session is not defined
at app/_components/talk/views/friends_list.coffee.js:1:16
at /home/xyz/web/edp/.meteor/local/build/server/server.js:298:12
at Array.forEach (native)
at Function._.each._.forEach (/home/xyz/.meteorite/meteors/meteor/
    meteor/9bb2b5447e845c4f483df5e9b42a2c1de5ab909b/
    dev_bundle/lib/node_modules/underscore/underscore.js:78:11)

这是我的目录结构(我已经更改了文件的名称):

├── _components
│   ├── project_form
│   │   └── client
│   │       ├── lib
│   │       │   └── ...
│   │       ├── project_info
│   │       │   ├── x1.coffee
│   │       │   ├── x2.html
│   │       │   ├── x3.coffee
│   │       │   └── x4.html
│   │       └── views
│   │           ├── x5.coffee
│   │           └── x6.html
│   ├── README.md
│   └── talk
│       └── client
│             ├── x7.coffee
│             ├── x8.html
│             ├── x9.coffee
│             ├── x10.html
│             ├── x11.coffee
│             ├── x12.html
│             ├── x13.coffee
│             ├── x14.html
│             └── x15.less

如果我把目录结构改成下面这样,meteor就可以正常运行了。真不知道为什么,怎么会这样呢?我认为文件加载顺序可能会有所不同。但我无法弄清楚。

├── _components
│   ├── project_form
│   │   └── client
│   │       ├── lib
│   │       │   └── ...
│   │       ├── project_info
│   │       │   ├── x1.coffee
│   │       │   ├── x2.html
│   │       │   ├── x3.coffee
│   │       │   └── x4.html
│   │       └── views
│   │           ├── x5.coffee
│   │           └── x6.html
│   ├── README.md
│   └── talk
│       └── client
│           └── views
│               ├── x7.coffee
│               ├── x8.html
│               ├── x9.coffee
│               ├── x10.html
│               ├── x11.coffee
│               ├── x12.html
│               ├── x13.coffee
│               ├── x14.html
│               └── x15.less
4

4 回答 4

74

虽然以上是正确的,但如果您使用的是较新版本的 Meteor,则默认情况下不再支持 Session。停止服务器,打开终端并写入:

meteor add session

如果你正在寻找 ReactiveVar 和 ReactiveDict,同样的问题。打开终端并写入:

meteor add reactive-var reactive-dict 
于 2016-04-08T15:49:45.933 回答
19

这可能会发生,因为Session仅适用于客户端,并且app/_components/talk/views/friends_list.coffee.js它也将在服务器上运行。

您可能希望将所有视图/客户端内容移动到/client目录中或将其放置在:

if(Meteor.isClient) {

}
于 2013-06-13T17:29:38.277 回答
10

根据最新的 Meteor ^1.5.1

goto.meteor/packages文件并session在最后一行添加。

注意:你的流星服务器是否启动并不重要。


旧答案

停止流星服务器并运行以下命令。

meteor add session
于 2016-04-21T11:12:14.183 回答
2

在我使用mupx部署到DigitalOcean后,这发生在我身上。

会话在本地主机上开发时有效,但在部署后我得到了ReferenceError: Session is not defined

session添加到流星包并重新部署后,错误已修复。

于 2016-08-17T17:50:05.447 回答