@dima89e

Faker JS Node JS в чем ошибка?

import faker from '@fakerjs/faker';

const getRandomArrayValue = arr => arr[Math.floor(Math.random() * arr.length)];

const collections = ['street', 'black', 'casual', 'orange', 'line'];
const colors = ['purpure', 'yellow', 'orange', 'black', 'white'];
const compositions = ['cotton', 'synthetics', 'polyester'];
const clothTypes = ['t-shirts', 'long-sleeves', 'hoodie', 'outerwear'];
const images = [
	'/img/clothes/cloth-hoodie-1.png',
	'/img/clothes/cloth-long-sleeves-1.png',
	'/img/clothes/cloth-long-sleeves-2.png',
	'/img/clothes/cloth-outerwear-1.png',
	'/img/clothes/cloth-outerwear-2.png',
	'/img/clothes/cloth-t-shirts-1.png',
	'/img/clothes/cloth-t-shirts-2.png',
];
const lineImages = [
	'/img/black-t.png',
	'/img/violet-t.png',
	'/img/orange-t.png',
];
const fabricTypes = [
	'natural',
	'non-natural',
	'mixed',
	'non-woven',
	'stockinette',
];
const features = [
	'breathable material, knitwear',
	'contrasting color',
	'soft fabric',
	'hood, pockets',
];
const collars = [
	'polo',
	'shirt-rack',
	'apache',
	'tangerine',
	'golf',
	'round neck',
];
const sleeves = ['long', 'short'];
const seasons = ['demi-season', 'all season'];
const upperMaterials = [
	'synthetic material',
	'quilted jacket fabric',
	'eco leather',
	'denim',
];
const liningMaterials = ['taffeta', 'viscose', 'polyester', 'chiffon', 'satin'];

export async function up(db) {
	return db.collection('cloth').insertMany(
		[...Array(50)].map(async () => {
			const type = clothTypes[Math.floor(Math.random() * clothTypes.length)];
			const characteristics = [
				{
					type: 't-shirts',
					color: getRandomArrayValue(colors),
					collar: getRandomArrayValue(collars),
					silhouette: 'straight',
					print: 'chocolate, print, melange',
					decor: faker.datatype.boolean(),
					composition: getRandomArrayValue(compositions),
					season: getRandomArrayValue(seasons),
					collection:
						collections[Math.floor(Math.random() * collections.length)],
				},
				{
					type: 'long-sleeves',
					color: getRandomArrayValue(colors),
					collar: getRandomArrayValue(collars),
					silhouette: 'straight',
					print: 'chocolate, print, melange',
					decor: faker.datatype.boolean(),
					composition: getRandomArrayValue(compositions),
					features: getRandomArrayValue(features),
					fabricType: getRandomArrayValue(fabricTypes),
					sleeve: getRandomArrayValue(sleeves),
					season: getRandomArrayValue(seasons),
					collection:
						collections[Math.floor(Math.random() * collections.length)],
				},
				{
					type: 'hoodie',
					color: getRandomArrayValue(colors),
					collar: getRandomArrayValue(collars),
					silhouette: 'straight',
					print: 'chocolate, print, melange',
					decor: faker.datatype.boolean(),
					composition: getRandomArrayValue(compositions),
					features: getRandomArrayValue(features),
					fabricType: getRandomArrayValue(fabricTypes),
					sleeve: getRandomArrayValue(sleeves),
					clasp: faker.datatype.boolean(),
					season: getRandomArrayValue(seasons),
				},
				{
					type: 'outerwear',
					color: getRandomArrayValue(colors),
					collar: getRandomArrayValue(collars),
					decor: faker.datatype.boolean(),
					composition: getRandomArrayValue(compositions),
					features: getRandomArrayValue(features),
					upperMaterial: getRandomArrayValue(upperMaterials),
					liningMaterial: getRandomArrayValue(liningMaterials),
					collection:
						collections[Math.floor(Math.random() * collections.length)],
				},
			];
			const currentCharacteristics = characteristics.find(
				item => item.type === type
			);
			return {
				category: 'cloth',
				type,
				price: +faker.string.numeric(4).replace(/.{0,2}$/, 99),
				name: faker.lorem.sentence(2),
				description: faker.lorem.sentences(10),
				characteristics: currentCharacteristics,
				images:
					type === 't-shirts' && currentCharacteristics.collection === 'line'
						? [getRandomArrayValue(lineImages)]
						: images.filter(item => item.includes(type)),
				vendorCode: faker.string.numeric(4),
				inStock: faker.string.numeric(2),
				isBestseller: faker.datatype.boolean(),
				isNew: faker.datatype.boolean(),
				popularity: +faker.string.numeric(3),
				sizes: {
					s: faker.datatype.boolean(),
					l: faker.datatype.boolean(),
					m: faker.datatype.boolean(),
					xl: faker.datatype.boolean(),
					xxl: faker.datatype.boolean(),
				},
			};
		})
	)
}
export async function down(db) {
	return db.collection('cloth').deleteMany({});
}


Ошибка -
;
$ migrate-mongo up 
(node:14992) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version 
(Use `node --trace-warnings ...` to show where the warning was created) 
(node:14992) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version 
file:///D:/Sites/PROJECTS-REACT/rostelekom-shop/migrations/20240612103445-cloth.js:65 
                                        decor: faker.datatype.boolean(), 
                                                              ^ 
 
TypeError: Cannot read properties of undefined (reading 'boolean') 
    at file:///D:/Sites/PROJECTS-REACT/rostelekom-shop/migrations/20240612103445-cloth.js:65:28 
    at Array.map (<anonymous>) 
    at up (file:///D:/Sites/PROJECTS-REACT/rostelekom-shop/migrations/20240612103445-cloth.js:56:18) 
    at migrateItem (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\lib\actions\up.js:25:15) 
    at async pEachSeries (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\node_modules\p-each-series\index.js:8:23) 
    at async module.exports [as up] (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\lib\actions\up.js:51:3) 
 
Node.js v20.11.1
  • Вопрос задан
  • 78 просмотров
Решения вопроса 1
@fakerjs/faker !== @faker-js/faker
В том, который вы установили, нет никакого datatype.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы