0

流星版本:1.2.1

使用来自 themeteorchef 的基本框架

并使用包 themeteorchef:seeder

当我尝试在一个干净的新项目(没有基本启动器)中使用播种器包时,它工作正常。然而,在我从基础启动器创建的项目中,它Can't Wait Without A Fiber在调用 Seed 函数的代码部分引发错误。

当我尝试调用像findand之类的数据库函数时,同样的事情发生在我身上insertfibers添加到我的app.use库列表后,我将代码包含在 Fiber 函数中package.js

这是我的package.js文件

Package.describe({
  name: 'team:library',
  version: '0.0.1',
  // Brief, one-line summary of the package.
  summary: '',
  // URL to the Git repository containing the source code for this package.
  git: '',
  // By default, Meteor will default to using README.md for documentation.
  // To avoid submitting documentation, set this field to null.
  documentation: 'README.md'
});

Npm.depends({
  library: "link-to-a-github-commit",
  util: '0.10.3'
});

Package.onUse(function(api) {
  api.versionsFrom('1.2.1');
  api.use(['ecmascript', 'templating', 'check', 'mongo', 'kadira:flow-router', 'themeteorchef:seeder', 'fibers']);


  // Load the lib directory before all other files are loaded
  api.addFiles( 'lib/constants/tokens.js', 'server' );

  api.addFiles('client/templates/library-widget.html', 'client');
  api.addFiles('client/templates/library-widget.js', 'client');

  api.addFiles('client/templates/user-folder-list-widget.html', 'client');
  api.addFiles('client/templates/user-folder-list-widget.js', 'client');

  api.addFiles('client/templates/index.html', 'client');

  api.addFiles( 'collections/LibraryUsers.js', 'server' );
  api.export( 'LibraryUsers', 'server' );

  api.addFiles('server/startup.js', 'server');
  api.addFiles('server/methods/library-team.js', 'server');

});

Package.onTest(function(api) {
  api.use('ecmascript');
  api.use('tinytest');
  api.use('team:library');
  api.addFiles('library-tests.js');
});

我在我的包内的 server/startup.js 文件中调用 Seed,如下所示:

Seed( 'Products', {
  min: 5,
  environments: [ 'development', 'staging', 'production' ],
  model( index ) {
    return {
      name: faker.commerce.product(),
      price: faker.commerce.price()
    };
  }
});

我将它封装在 Fiber 中,如下所示

try {
  Fiber( function() {
    Seed( 'Products', {
      min: 5,
      environments: [ 'development', 'staging', 'production' ],
      model( index ) {
        return {
          name: faker.commerce.product(),
          price: faker.commerce.price()
        };
      }
    });
  });
} catch( error ) {
  console.log( error );
}

在我的包文件中包含纤维后,如上面的包文件所示。我得到的错误信息是

[ReferenceError: Fiber is not defined]

什么可能导致此错误?

4

1 回答 1

0

将以下行放在您的“Fiber(function() { ...”之前可能会解决该错误,因为它定义了您正在使用的“Fiber”对象:

Fiber = Npm.require('fibers');

或者只是这也可能有效,不确定:

Fiber = require("fibers")
于 2016-06-24T09:24:41.587 回答