2016-09-01 8 views
4

問題が見つかりません。誰でも私が間違っているのを見ている? このプロジェクトは、流星と反応で作られています。Marak/faker.jsでデータをインポートしようとするとエラーが発生する

私のインポートファイル:

import _ from 'lodash'; 
 
import { lorem, faker } from 'faker'; 
 
import { Comments } from '../../api/comments/comments'; 
 
import { insertComment } from '../../api/comments/methods.js'; 
 
import { Bert } from 'meteor/themeteorchef:bert'; 
 

 

 
Meteor.startup(() => { 
 
\t // Great place to generate some data 
 

 
\t // Check to see if data excists in the collection 
 
\t // See if the collection has any records 
 
\t const numberRecords = Comments.find({}).count(); 
 
\t if (!numberRecords) { 
 
\t \t // Generate some data... 
 
\t \t _.times(100,() => { 
 
\t \t \t const title = faker.lorem.title(); 
 
\t \t \t const content = faker.lorem.title(); 
 

 
\t \t \t insertComment.call({ 
 
\t \t \t \t title, content, 
 
\t \t \t }, (error) => { 
 
\t \t \t \t if (error) { 
 
\t \t \t   Bert.alert(error.reason, 'danger'); 
 
\t \t \t  } else { 
 
\t \t \t   target.value = ''; 
 
\t \t \t   Bert.alert('Comment added!', 'success'); 
 
\t \t \t  } 
 
\t \t \t }); 
 
\t \t }); 
 
\t } 
 
});

そして、これは私がコメントを書き込むために使用するメソッドファイルです:これは

import { Comments } from './comments'; 
 
import { SimpleSchema } from 'meteor/aldeed:simple-schema'; 
 
import { ValidatedMethod } from 'meteor/mdg:validated-method'; 
 
import { rateLimit } from '../../modules/rate-limit.js'; 
 

 
export const insertComment = new ValidatedMethod({ 
 
    name: 'comments.insert', 
 
    validate: new SimpleSchema({ 
 
    title: { type: String }, 
 
    content: { type: String }, 
 
    }).validator(), 
 
    run(comment) { 
 
    Comments.insert(comment); 
 
    }, 
 
}); 
 

 
rateLimit({ 
 
    methods: [ 
 
    insertComment, 
 

 
    ], 
 
    limit: 5, 
 
    timeRange: 1000, 
 
});

私の端末に入っているエラーコード: TypeError:未定義のプロパティ 'lorem'を読み取ることができません。

ご協力いただきまして誠にありがとうございます。

EDIT:

としては、Iからインポートを変更した提案 " '偽物' からインポート{Loremの、偽物};" 「fakerからfakerをインポートする」;

また、この「faker.lorem.title();」も変更されました。 〜 "faker.hacker.noun();"

ありがとうございました!

答えて

2

It looks like Fakerはデフォルトで、定数としてではなくfakerをエクスポートしています。だから、

import faker from 'faker'; 
// then use `faker.lorem` as you are currently doing 

または

import { lorem } from 'faker'; 
// then use `lorem` instead of `faker.lorem` 

現在、あなたが faker.loremを使用して、その後

import { lorem, faker } from 'faker'; 

とを行っている行う必要があり、そうloremインポートしているが使用されていません。インポートしようとしているfakerが定義されていないため、faker.lorem(...を呼び出すと、エラーとしてTypeError: Cannot read property 'lorem' of undefined.が例外としてスローされます。

+0

クールで、明確な説明とあなたの答えを書く時間をとってくれてありがとう!試してみよう。 – Deelux

+0

よかったです。私は一歩近づいています。私はあなたが言った変更を加えました。だから唯一の使用して: - >フェイカー 'からインポートフェイザー; そして、 "faker.lorem.title"を "faker.hacker.noun();"に変更しました。それはうまくいくようです。しかし、今私は、挿入メソッドと関係している新しいエラーを取得しています: 'comments.insert'を呼び出す結果の配信で例外:ReferenceError:ターゲットが定義されていません – Deelux

+0

私はまだエラーが発生しますが、フェカーからのデータ!再度、感謝します! – Deelux

関連する問題