admin管理员组文章数量:1353252
I can't seem to find my problem. Anyone see what I am doing wrong? This project is made with Meteor and React.
My import file:
import _ from 'lodash';
import { lorem, faker } from 'faker';
import { Comments } from '../../api/ments/ments';
import { insertComment } from '../../api/ments/methods.js';
import { Bert } from 'meteor/themeteorchef:bert';
Meteor.startup(() => {
// Great place to generate some data
// Check to see if data excists in the collection
// See if the collection has any records
const numberRecords = Comments.find({}).count();
if (!numberRecords) {
// Generate some data...
_.times(100, () => {
const title = faker.lorem.title();
const content = faker.lorem.title();
insertComment.call({
title, content,
}, (error) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
target.value = '';
Bert.alert('Comment added!', 'success');
}
});
});
}
});
I can't seem to find my problem. Anyone see what I am doing wrong? This project is made with Meteor and React.
My import file:
import _ from 'lodash';
import { lorem, faker } from 'faker';
import { Comments } from '../../api/ments/ments';
import { insertComment } from '../../api/ments/methods.js';
import { Bert } from 'meteor/themeteorchef:bert';
Meteor.startup(() => {
// Great place to generate some data
// Check to see if data excists in the collection
// See if the collection has any records
const numberRecords = Comments.find({}).count();
if (!numberRecords) {
// Generate some data...
_.times(100, () => {
const title = faker.lorem.title();
const content = faker.lorem.title();
insertComment.call({
title, content,
}, (error) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
target.value = '';
Bert.alert('Comment added!', 'success');
}
});
});
}
});
And this is the method file I use to write the ment:
import { Comments } from './ments';
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: 'ments.insert',
validate: new SimpleSchema({
title: { type: String },
content: { type: String },
}).validator(),
run(ment) {
Comments.insert(ment);
},
});
rateLimit({
methods: [
insertComment,
],
limit: 5,
timeRange: 1000,
});
This is the error code I am getting in my terminal: TypeError: Cannot read property 'lorem' of undefined.
Any help is highly appreciated.
EDIT:
As suggested I made the changes to the import from "import { lorem, faker } from 'faker';" to "import faker from 'faker';"
I also changed this "faker.lorem.title();" to "faker.hacker.noun();"
Thanks Guig!
Share Improve this question edited Sep 3, 2016 at 9:48 Deelux asked Sep 1, 2016 at 20:03 DeeluxDeelux 1,1952 gold badges12 silver badges26 bronze badges1 Answer
Reset to default 9It looks like Faker is exporting faker
as a default, and not as a constant. So you should do
import faker from 'faker';
// then use `faker.lorem` as you are currently doing
or
import { lorem } from 'faker';
// then use `lorem` instead of `faker.lorem`
Currently, you are doing
import { lorem, faker } from 'faker';
and then using faker.lorem
, so the lorem
you're importing is not used. And the faker
you are trying to import is undefined, so calling faker.lorem(...
throws an error TypeError: Cannot read property 'lorem' of undefined.
as excepted.
本文标签: javascriptError when trying to import data with MarakfakerjsStack Overflow
版权声明:本文标题:javascript - Error when trying to import data with Marakfaker.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743914597a2560998.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论