【问题标题】:Meteor Session is not defined流星会话未定义
【发布时间】:2013-06-13 16:41:32
【问题描述】:

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

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

如果我将目录结构更改为以下内容, 流星运行正常。我真的不知道为什么,怎么会发生? 我认为文件加载顺序可能会有所不同。 但我想不通。

├── _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

【问题讨论】:

    标签: session meteor


    【解决方案1】:

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

    meteor add session
    

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

    meteor add reactive-var reactive-dict 
    

    【讨论】:

    • 你需要去终端导航meteor项目并运行命令行“meteor add session”
    • 非常感谢伙计。我很好奇前 5 分钟发生了什么,但这解决了我的问题。当您在 .meter/packages 中包含会话时,您还可以添加会话包
    • 我想这是为了激励人们改用 reactiveVars。目前,社区滥用 Session 包。
    • @FranciscoGutiérrez 我非常同意。对于希望开始使用 ReactiveVars 和 Dicts 而不是专门使用会话的人来说,这是一个很棒的教程:themeteorchef.com/snippets/…
    【解决方案2】:

    这可能是因为Session 仅在客户端上运行,而在app/_components/talk/views/friends_list.coffee.js 上它也将在服务器上运行。

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

    if(Meteor.isClient) {
    
    }
    

    【讨论】:

      【解决方案3】:

      根据最新的 Meteor ^1.5.1

      转到 .meteor/packages 文件并在最后一行添加 session

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


      旧答案

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

      meteor add session
      

      【讨论】:

        【解决方案4】:

        这发生在我使用mupx 部署到DigitalOcean 之后。

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

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

        【讨论】:

        • 你有一个很好的教程的链接,用于将流星应用程序部署到 DO?
        • youtube.com/watch?v=nz2p9xIT2es :使用 mupx 部署 Meteor 应用程序。遗憾的是,它仅适用于 Meteor 1.3.5 及以下版本。
        猜你喜欢
        • 2017-07-24
        • 2015-07-02
        • 2015-10-06
        • 1970-01-01
        • 2013-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-15
        相关资源
        最近更新 更多