Uncaught Error when using prisma inside `app/src/server/utils.ts`
While working on creating jobs, I created a utility for logging inside the
server/utils.ts
I wasn't checking the front-end from time to time as I was testing the job using postman.
However upon visiting the front-end @ localhost it doesn't work, it says uncaught error.
This was hard to debug as the terminal says wasp is building correctly, it's basically a runtime error. Had to check the which commit this started and check the code changes. At first I thought I did something wrong in the jobs.
Is this an expected behavior?
* I attached the browser console error
Here is the code:
17 Replies
Hi @mm. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the provided information, it seems like you're trying to use Prisma in a utility function for logging. However, there might be an issue with how Prisma is being initialized or used.
One of the common issues with Prisma is that it might not be initialized correctly. For example, in this issue (https://github.com/wasp-lang/wasp/issues/427), the user had to manually import and initialize PrismaClient to make it work.
Another common issue is when there are no entities defined in the
main.wasp
file, the server might crash with a Prisma error as described in this issue (https://github.com/wasp-lang/wasp/issues/398).
Also, there might be an issue with the environment variable DATABASE_URL
not being found as described in this issue (https://github.com/wasp-lang/wasp/issues/1321) and this issue (https://github.com/wasp-lang/wasp/issues/1282).
Please make sure that Prisma is correctly initialized and the DATABASE_URL
environment variable is correctly set. If the problem persists, it might be a good idea to open an issue on the Wasp GitHub repository.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @mm, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Kapa is not really helpful here 😄
Are you importing this logger on the client? Or are you importing some file on the client that imports the logger? I see the errors originates from the
config.ts
file.
Importing server code on the client is not really possible 🙂 e.g. the process
variable exists only in Node.jsNo I'm only using the logger on the server side
Yes it says config.ts
you mean if it's an issue with config.ts high probability that it's being used on client side?
So there is a probability that this utility is being considered as client code? what do you think that's why I can't put back-end specific code in it?
what I did to make it work is to simply pass the PrismaClient
I'm using it inside a job
Simply put, you shouldn't import
server/utils.ts
in your client code like React components.
I'm not sure if you are importing it directly in some React component or you are importing it in the config.ts
file and then import importing the config.ts
in some React component.
Please check all the import Something from Something
bits in your client code to make sure it's not happening.I'm not using it directly inside a client code
I only used it for jobs in this case
And do you have a
config.ts
file?nope
let me double check
these are the files that make uses the utils
Where does the browser take you when you click on the filename in the error message?
config.ts:41:20
what do you see?I'll check later after deployment. or can I run wasp start while deploying??
Here's the file
Wohooo @mm, you just became a Waspeteer level 4!
When I have the time I will try this out in a fresh opensaas setup. I kinda re-organized the directories for this project maybe that's causing this? though I'm not sure if it's supposed to be an issue.
You are importing
wasp/server/config
on the client?Nope
Could you maybe share your app with me? Via a public Github repo or via a zip file?