Reputation: 146
I am trying to run Prisma to integrate with MySQL database using node js servers. After migrating the Prisma schema to the MySql database I get the following error on Mac air m1 I have already verified that the DATABASE URL IS CONFIGURED PROPERLY. I have tried clearing the cache forcefully, reinstalling npm, rebooting the pc, and restarting VsCode.
EPERM: operation not permitted, utime '/Users/apple/.cache/prisma/master/bcc2ff906db47790ee902e7bbc76d7ffb1893009/darwin-arm64/prisma-fmt' apple@Apples-MacBook-Air servers %
When I try to run the server.js file I get the following error
@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues at new PrismaClient (/Users/apple/Desktop/react-i/servers/node_modules/.prisma/client/index.js:3:11) at Object. (/Users/apple/Desktop/react-i/servers/authenticate.js:7:16) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (/Users/apple/Desktop/react-i/servers/server.js:7:18) at Module._compile (node:internal/modules/cjs/loader:1101:14)
running npx prisma generate gives the first error again
Any help is appreciated
Here is the relevant server code snippet
const { PrismaClient } = require("@prisma/client");
const crypto = require('crypto');
const express = require('express');
const route = express.Router();
const jwt = require('jsonwebtoken');
const prisma = new PrismaClient();
const addUserToDb = async user => {
try {
const newUser = await prisma.users.create({
data: {
email: user.email,
username: user.username,
password: hashPassword(user.password),
isAdmin: true,
},
});
console.log(JSON.stringify(newUser));
} catch (e) {
console.error(e);
return 'problem adding user to db';
}
return 'user added to db';
};
const hashPassword = password => {
let salt = crypto.randomBytes(16).toString('hex');
hashedpwd = crypto.pbkdf2Sync(password, salt, 1000, 64, 'sha512');
console.log(hashedpwd);
return hashedpwd;
};
const generateToken = (user, time = '300s') =>
jwt.sign(user, process.env.ACCESS_TOKEN_SECRET, { expiresIn: time });
route.post('/register', (req, res) => {
let newUser = req.body.userRegister;
const accessToken = jwt.sign(newUser, process.env.ACCESS_TOKEN_SECRET);
res.json({ user: addUserToDb(newUser), token: accessToken });
});
module.exports = route;
//prisma.schema code
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Users {
id String @id @default(uuid())
username String @unique @db.VarChar(255)
email String? @unique @db.VarChar(255)
password String @db.VarChar(255)
refreshToken String?
passwordResetToken String?
profileImgUrl String?
customers Customers?
role String @default("user")
@@map(name: "users")
}
model Services {
id Int @id @default(autoincrement())
orders Orders[]
title String
description String
SAC String? @unique @db.VarChar(255)
@@map(name: "services")
}
model Customers {
customers Users @relation(fields: [customerId], references: [id])
customerId String @unique
firstName String
lastName String
phoneNumber Int
address String
State String
Pincode Int
City String?
orders Orders[]
@@map(name: "customers")
}
model Orders {
id Int @id @default(autoincrement())
value Float
createdAt DateTime @default(now())
service Services @relation(fields: [serviceId], references: [id])
serviceId Int
customer Customers @relation(fields: [customerId], references: [customerId])
customerId String
@@map(name: "orders")
}
model Reviews {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
starRating Int
content String?
@@map(name: "reviews")
}
Upvotes: 3
Views: 4316
Reputation: 1
If sometimes it does not work remove node_modules
:
sudo rm -rf node_modules
And then:
npm install
or
yarn install
Upvotes: 0
Reputation: 141
In my case. stopping the Node process which was running in the background solved the issue
Upvotes: 5
Reputation: 146
Delete the cached Prisma folder at this directory /Users/<your_apple_username>/.cache/
and reinitialize Prisma to get it working again
Upvotes: 6
Reputation: 3
What helped me with the problem was to remove /Users/apple/.cache/prisma
directory as @Ilamuhil mentioned, but instead of installing prisma globally again from npm or yarn, i've just run prisma migrate dev
having it installed only locally in my project, and it worked.
Upvotes: 0