【问题标题】:Can't Wait Without A Fiber没有光纤就等不及了
【发布时间】:2016-10-25 23:22:00
【问题描述】:

流星版本:1.2.1

使用来自 themeteorchef 的 Base Framework

并使用包 themeteorchef:seeder

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

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

这是我的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]

什么可能导致了这个错误?

【问题讨论】:

    标签: meteor node-fibers


    【解决方案1】:

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

    Fiber = Npm.require('fibers');
    

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

    Fiber = require("fibers")
    

    【讨论】:

      猜你喜欢
      • 2017-11-04
      • 2017-08-08
      • 2021-10-06
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 2015-09-22
      • 2015-12-21
      相关资源
      最近更新 更多