【问题标题】:Meteor 1.4 Aldeed Collection2 not working out of the boxMeteor 1.4 Aldeed Collection2 无法开箱即用
【发布时间】:2017-05-15 07:51:16
【问题描述】:

我刚刚创建了一个新项目。

这些是我添加到项目中的包:

aldeed:collection2-core@2.0.0
aldeed:autoform

我还安装了 npm 包,meteor npm install --save simpl-schema

我创建了一个/lib 文件夹。

在其中,我使用以下代码创建了一个common.js 文件:

var Books = new Mongo.Collection("books");

var Schemas = {};

Schemas.Book = new SimpleSchema({
    title: {
        type: String,
        label: "Title",
        max: 200
    },
    author: {
        type: String,
        label: "Author"
    },
    copies: {
        type: SimpleSchema.Integer,
        label: "Number of copies",
        min: 0
    },
    lastCheckedOut: {
        type: Date,
        label: "Last date this book was checked out",
        optional: true
    },
    summary: {
        type: String,
        label: "Brief summary",
        optional: true,
        max: 1000
    }
});

Books.attachSchema(Schemas.Book);

我一重新启动应用程序,它就崩溃了,给我丢了这个:

=> Exited with code: 1
W20161231-01:03:28.126(-5)? (STDERR) /home/mehdi/.meteor/packages/meteor-tool/.1.4.2_3.17tso1e++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
W20161231-01:03:28.127(-5)? (STDERR)                        throw(ex);
W20161231-01:03:28.127(-5)? (STDERR)                        ^
W20161231-01:03:28.127(-5)? (STDERR) 
W20161231-01:03:28.127(-5)? (STDERR) TypeError: Cannot read property 'definitions' of undefined
W20161231-01:03:28.127(-5)? (STDERR)     at /home/mehdi/workspace/collection/node_modules/simpl-schema/dist/SimpleSchema.js:778:39
W20161231-01:03:28.128(-5)? (STDERR)     at Function._.each._.forEach (/home/mehdi/workspace/collection/node_modules/underscore/underscore.js:158:9)
W20161231-01:03:28.128(-5)? (STDERR)     at checkSchemaOverlap (/home/mehdi/workspace/collection/node_modules/simpl-schema/dist/SimpleSchema.js:777:24)
W20161231-01:03:28.128(-5)? (STDERR)     at SimpleSchema.extend (/home/mehdi/workspace/collection/node_modules/simpl-schema/dist/SimpleSchema.js:407:7)
W20161231-01:03:28.128(-5)? (STDERR)     at new SimpleSchema (/home/mehdi/workspace/collection/node_modules/simpl-schema/dist/SimpleSchema.js:96:10)
W20161231-01:03:28.128(-5)? (STDERR)     at [object Object].c2AttachSchema [as attachSchema] (packages/aldeed:collection2-core/collection2.js:35:10)
W20161231-01:03:28.128(-5)? (STDERR)     at meteorInstall.lib.common.js (lib/common.js:33:7)
W20161231-01:03:28.128(-5)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:181:9)
W20161231-01:03:28.128(-5)? (STDERR)     at require (packages/modules-runtime.js:106:16)
W20161231-01:03:28.129(-5)? (STDERR)     at /home/mehdi/workspace/collection/.meteor/local/build/programs/server/app/app.js:60:1

知道有什么问题吗?

【问题讨论】:

  • 出于好奇,为什么通过meteor add 安装collection2 而通过npm 安装simple-schema? collection2 自动添加简单模式。 collection2-core 你也npm install this simple-schema 吗?
  • @MichelFloyd 我按照 Aldeed 自己的安装说明通过npm 安装了它collection2-core@2.0.0。我也是npm installsimple-schema,但是出现同样的错误。
  • 您在哪里找到这些说明?没有提到 npm here
  • 嘿伙计,新年快乐! :) 我在这里得到了说明:github.com/aldeed/meteor-collection2/blob/master/README.md
  • 嗯,好的。您是否按照该页面上的说明检查了版本文件?

标签: meteor schema meteor-autoform meteor-collection2


【解决方案1】:

试试这个....

var Books = new Mongo.Collection("books");

Books.schema = new SimpleSchema({
    title: {
        type: String,
        label: "Title",
        max: 200
    },
    author: {
        type: String,
        label: "Author"
    },
    copies: {
        type: SimpleSchema.Integer,
        label: "Number of copies",
        min: 0
    },
    lastCheckedOut: {
        type: Date,
        label: "Last date this book was checked out",
        optional: true
    },
    summary: {
        type: String,
        label: "Brief summary",
        optional: true,
        max: 1000
    }
});

Books.attachSchema(Books.schema);

【讨论】:

    【解决方案2】:

    或者,您也可以将架构附加为:

    const Books = new Mongo.Collection("books");
    Books.attachSchema(new SimpleSchema({
      title: {
        type: String,
        label: "Title",
        max: 200
      },
      ...
    }));
    

    【讨论】:

      【解决方案3】:

      在 NPM 包 simpl-schema 中使用时,SimpleSchema 不被视为全局变量。您必须确保:

      import SimpleSchema from 'simpl-schema';
      

      【讨论】:

        猜你喜欢
        • 2016-12-20
        • 1970-01-01
        • 2016-10-08
        • 2016-05-06
        • 2015-06-25
        • 2017-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多