danimiclos
danimiclos
WWasp-lang
Created by danimiclos on 5/4/2024 in #đŸ™‹questions
TypeError: Cannot read properties of undefined
Hello @martinsos, it's working now with your code. Thank you!
33 replies
WWasp-lang
Created by danimiclos on 5/4/2024 in #đŸ™‹questions
TypeError: Cannot read properties of undefined
@martinsos sorry, I didn't saw your reply. I will be back on this project tomorrow and, then I wil be able to test and give you a response. Thanks!
33 replies
WWasp-lang
Created by danimiclos on 5/4/2024 in #đŸ™‹questions
TypeError: Cannot read properties of undefined
Hello @sodic, thank you for your attention. I'm happy to inform you that the seeding process is now working as expected. The issue was resolved by importing the PrismaClient. Initially, I did not try this solution as I was following the example provided in the documentation where there was no mention of importing the PrismaClient in the code. I apologize for the code block formatting. I often forget how to format code when pasting it. Here's my solution, I hope it looks good in the chat:
import { PrismaClient } from '@prisma/client'
import { createTipoEPI } from "../epis/actions";

import fs from 'fs';
import csv from 'csv-parser';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const prisma = new PrismaClient()

export const seedTipoEPI = async (prisma) => {
console.log(`Current directory: ${process.cwd()}`);

const results = [];
const csvFilePath = resolve(__dirname, '../../../../src/seeds/tipoepi.csv');

console.log(prisma.tipoEPI);


fs.createReadStream(csvFilePath)
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', async () => {
for (const item of results) {
await createTipoEPI({
nome: item.nome // Yes, 'nome' is the correct field
}, { entities: { TipoEPI: prisma.tipoEPI } }); // Mock the context structure expected by actions.js
}
console.log('Successfully seeded TipoEPI data.');
});
prisma.$disconnect()
}

seedTipoEPI().catch((e) => {
console.error(e);
prisma.$disconnect();
});
import { PrismaClient } from '@prisma/client'
import { createTipoEPI } from "../epis/actions";

import fs from 'fs';
import csv from 'csv-parser';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const prisma = new PrismaClient()

export const seedTipoEPI = async (prisma) => {
console.log(`Current directory: ${process.cwd()}`);

const results = [];
const csvFilePath = resolve(__dirname, '../../../../src/seeds/tipoepi.csv');

console.log(prisma.tipoEPI);


fs.createReadStream(csvFilePath)
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', async () => {
for (const item of results) {
await createTipoEPI({
nome: item.nome // Yes, 'nome' is the correct field
}, { entities: { TipoEPI: prisma.tipoEPI } }); // Mock the context structure expected by actions.js
}
console.log('Successfully seeded TipoEPI data.');
});
prisma.$disconnect()
}

seedTipoEPI().catch((e) => {
console.error(e);
prisma.$disconnect();
});
33 replies
WWasp-lang
Created by danimiclos on 5/4/2024 in #đŸ™‹questions
TypeError: Cannot read properties of undefined
@kapa.ai I've changed my code again commenting the action call just to check if there is a prisma.tipoEPI: import { PrismaClient } from '@prisma/client' import { createTipoEPI } from "../epis/actions"; import fs from 'fs'; import csv from 'csv-parser'; import { fileURLToPath } from 'url'; import { dirname, resolve } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const prisma = new PrismaClient() export const seedTipoEPI = async (prisma) => { console.log(Current directory: ${process.cwd()}); const results = []; const csvFilePath = resolve(__dirname, '../../../../src/seeds/tipoepi.csv'); console.log(prisma.tipoEPI); console.log('Successfully seeded TipoEPI data.'); // }); prisma.$disconnect() } seedTipoEPI().catch((e) => { console.error(e); prisma.$disconnect(); }); But I'm still getting errors at the end, even without use any action. The result now is: [ Db !] TypeError: Cannot read properties of undefined (reading 'tipoEPI') [ Db !] at seedTipoEPI (/home/daniel/projects/waspprojects/safemate/src/seeds/dbEpiTypeSeed.js:20:24) [ Db !] at <anonymous> (/home/daniel/projects/waspprojects/safemate/src/seeds/dbEpiTypeSeed.js:40:3) [ Db !] at ModuleJob.run (node:internal/modules/esm/module_job:218:25) [ Db !] at async ModuleLoader.import (node:internal/modules/esm/loader:323:24) [ Db !] at async loadESM (node:internal/process/esm_loader:28:7) [ Db !] at async handleMainPromise (node:internal/modules/run_main:120:12)
33 replies
WWasp-lang
Created by danimiclos on 5/4/2024 in #đŸ™‹questions
TypeError: Cannot read properties of undefined
@kapa.ai using console.log(prisma) returns undefined. my whole seeding code is as follow: import { createTipoEPI } from "../epis/actions"; import fs from 'fs'; import csv from 'csv-parser'; import { fileURLToPath } from 'url'; import { dirname, resolve } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); export const seedTipoEPI = async (prisma) => { console.log(Current directory: ${process.cwd()}); const results = []; const csvFilePath = resolve(__dirname, '../../../../src/seeds/tipoepi.csv'); console.log(prisma); fs.createReadStream(csvFilePath) .pipe(csv()) .on('data', (data) => results.push(data)) .on('end', async () => { for (const item of results) { await createTipoEPI({ nome: item.type }, { entities: { TipoEPI: prisma.tipoEPI } }); } console.log('Successfully seeded TipoEPI data.'); }); } seedTipoEPI().catch((e) => { console.error(e); prisma.$disconnect(); }); Is there any way I should initialize prisma on the wasp db seed command? When I dot wasp start the the prisma client must be initializing since I have access to the database and actions.
33 replies
WWasp-lang
Created by danimiclos on 5/4/2024 in #đŸ™‹questions
TypeError: Cannot read properties of undefined
@kapa.ai I've changed the code in the seed function at await createTipoEPI({... and now I got almost the same error: [ Db ] > [email protected] bundle [ Db ] > rollup --config --silent [ Db ] [ Db ] Current directory: /home/daniel/projects/waspprojects/safemate/.wasp/out/server [ Db ] Running seed: seedTipoEPI [ Db ] Current directory: /home/daniel/projects/waspprojects/safemate/.wasp/out/server [ Db !] /home/daniel/projects/waspprojects/safemate/src/seeds/dbEpiTypeSeed.js:27 [ Db !] entities: { TipoEPI: prisma.tipoEPI } [ Db !] ^ [ Db !] [ Db !] [ Db !] TypeError: Cannot read properties of undefined (reading 'tipoEPI') [ Db !] at CsvParser.<anonymous> (/home/daniel/projects/waspprojects/safemate/src/seeds/dbEpiTypeSeed.js:27:41) [ Db !] at CsvParser.emit (node:events:519:28) [ Db !] at endReadableNT (node:internal/streams/readable:1696:12) [ Db !] at process.processTicksAndRejections (node:internal/process/task_queues:82:21) [ Db !] [ Db !] Node.js v21.6.2 any other idea? Maybe for some reason the TipoEPI isn't initialyzing? (edited)
33 replies
WWasp-lang
Created by danimiclos on 5/4/2024 in #đŸ™‹questions
TypeError: Cannot read properties of undefined
Hello @kapa.ai are you there now?
33 replies
WWasp-lang
Created by danimiclos on 5/4/2024 in #đŸ™‹questions
TypeError: Cannot read properties of undefined
@kapa.ai I've changed the code in the seed function at await createTipoEPI({... and now I got almost the same error: [ Db ] > [email protected] bundle [ Db ] > rollup --config --silent [ Db ] [ Db ] Current directory: /home/daniel/projects/waspprojects/safemate/.wasp/out/server [ Db ] Running seed: seedTipoEPI [ Db ] Current directory: /home/daniel/projects/waspprojects/safemate/.wasp/out/server [ Db !] /home/daniel/projects/waspprojects/safemate/src/seeds/dbEpiTypeSeed.js:27 [ Db !] entities: { TipoEPI: prisma.tipoEPI } [ Db !] ^ [ Db !] [ Db !] [ Db !] TypeError: Cannot read properties of undefined (reading 'tipoEPI') [ Db !] at CsvParser.<anonymous> (/home/daniel/projects/waspprojects/safemate/src/seeds/dbEpiTypeSeed.js:27:41) [ Db !] at CsvParser.emit (node:events:519:28) [ Db !] at endReadableNT (node:internal/streams/readable:1696:12) [ Db !] at process.processTicksAndRejections (node:internal/process/task_queues:82:21) [ Db !] [ Db !] Node.js v21.6.2 any other idea? Maybe for some reason the TipoEPI isn't initialyzing?
33 replies