nextjs and prisma application getting error when publish to vercel - next.js

im using nextjs with prisma ,and my application is published on vercel, and today i changed my prisma Schema and generate and migrated the changes and for some reason when im in devlopment the prisma controllers works perfect,
but when i upload my application to vercel im getting error on build, and I'm pretty sure the problem is that vercel doesn't recognize the changes I made to the schema bec the error im getting is realted to the changes that i did to the schema.
i tried to generate and migrated again and stil it dosent worked.
and this is the error im getting:
Type error: Type '{ todoTypeTitle: string; }' is not assignable to type 'Enumerable | undefined'.
Object literal may only specify known properties, and 'todoTypeTitle' does not exist in type 'Enumerable'.

Your build script should include npx prisma generate command to ensure that your schema changes are correctly reflected in the generated Prisma Client.
Here's an example that demonstrates how npx prisma generate command can be a part of build script. In the example migrate deploy is also the part of the script, you can omit it if you are not using Prisma Migrate.

Related

Build Next.js app before deploying via Serverless Component

We're using the Next.js Serverless Component from: https://serverless-nextjs.com/ to deploy our Next.js app to AWS using the Serverless framework.
It takes around 7-8 mins for the app to be built and then deployed to AWS.
We were hoping to instead build the app up-front and then deploy the pre-built code...
You can tell Serverless to not build and just do the deployment with build.enabled: false:
# serverless.yml
myNextApplication:
component: "#sls-next/serverless-component#3.7.0"
inputs:
bucketName: our-bucket-name
build:
enabled: false
However when we run yarn next build the app is built under ./next.
When serverless builds the app it stores the state in .stateless and the files in .stateless_nextjs. So therefore the next build isn't compatible with deploying a prebuilt app...
This means if we try and build the app and then call serverless after we get the following error:
myNextApplication › Error: ENOENT: no such file or directory, open '/Users/cameron/Projects/nextjs-serverless/.serverless_nextjs/default-lambda/manifest.json'
So how do you build the app first and then deploy the build using Next.js Serverless Component?
Versions:
"dependencies": {
"next": "12.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"serverless": "2.72.2"
},
component: "#sls-next/serverless-component#3.7.0"
The reason is probably wrong next.js middleware setup. manifest.json is built upon simulated requests that goes through nextjs middlewares. please refer to this stackoverflow answer.
nextjs middleware had some structural changes around v12.x that requires migration. it's hard to figure out what's wrong because it gives little or no warning messages and it builds okay. I had similar issues too.
Solution
check if your deploy includes proper package lock file(yarn.lock, package-lock.json...) so that fixed version of next.js is included when deploying.
check latest middleware examples from github repo and try match middleware file structure and code.
check out nextjs middleware migration guide mentioned earlier; try build in local environment and make sure manifest.json is created.

Next.js SSR with local SQLite: "unable to open database file"

I'm creating a small Next.js app with a local ~250MB SQLite db. I put the mydb.sqlite file in the root folder of my project, and import it using better-sqlite3:
import sqlite from 'better-sqlite3';
export const db = sqlite('./mydb.sqlite');
I have a couple of server-side rendered (SSR) routes that query data from the DB and renders them in a React page. This works well locally with next dev on localhost:3000. However, when I deploy to Vercel, and visit the same SSR page, I get the error at runtime:
ERROR SqliteError: unable to open database file
It's worthy to note that since the DB is >100MB, I cannot commit it to git. Instead, in my build phase, I download it:
// package.json
"scripts": {
"build": "curl $DB_URL -o mydb.sqlite && next build",
},
I also have some statically-generated (SSG) pages which query the DB, and those pages are correctly generated. Only SSR pages have that error at runtime.
Is there something I forgot to do? Must I commit the db to git? Should I configure the webpack config?
I looked on the internet for sqlite + next.js, but it always involve prisma; I prefer plain SQL queries.
SSR pages on vercel are rendered by their serverless functions. These functions don't have your sqllite file layered inside and thus you get the unable to open error.

how to run amplify codegen in where codegen is already configured?

we have a project repo where backend team have added new apis.
other developers have run and configured amplify and codegen.
now I want to add these new queries and their types.
when I run amplify codegen i get this error:
Please download the schema.graphql or schema.json and place in C:\leag\nevClon\newwebsite before adding codegen when not in an amplify project
and when i run amplify add codegen it says Codegen support only one GraphQL API per project.
could someone guide me whats the right way to do that.
I've seen this problem in the past. Things I've tried include ...
Make sure you are in the correct amplify environment.
Run amplify pull to ensure you are up to date.
Try re-initializing using amplify init
When all else fails, try re-cloning the repository.

Unable to change the default project to deploy my project on firebase hosting

i am trying to deploy my project on firebase hosting. And whenever i am using firebase init it is showing error in terminal as "firebaserc already has a default project " and it exit with that error
i have tried firebase logout and firebase login again . And used "firebase use" command also to change the project but it is still performing the firebase init action on the default project
i want to remove that default project
If you look very carefully at the messaging, it's saying that the name of the file is ".firebaserc" with a leading dot. This file indicates that firebase init was already run in this folder, and the contents of that file describe which project it's connected to (flairboat-48f7b). If you no longer want that file, delete it and start over. Since it starts with a dot, it might be hidden from normal view, but you can be sure that it exists.
you should write:
firebase use --add
and it work! You get the option to choose the preject from firebase.
I ran into the same issue.
Due to a small mistake in setting up the project in firebase, I had to delete it.
But later, I realized that my application NEEDS the default project to be hosted from firebase.
Since I found no shortcuts and running out of time, I did "this" to fix the issue in 10 minutes...with a 5-Step-Process. This is not a "Clever tip". But if you want things up and running soon, you can try this...
Create a new project (in my case, it's React project in VS Code IDE) using - npx create-react-app newprojectname to create a new react project with a different file name.(Don't delete or replace your previous project yet... )
While the new project is being created, create a new project in firebase to host your project.
Copy the folder from your old project that has all your work (it's "src" folder in case of React) and replace the "src" folder in the new project you created in your local machine.
Install all dependencies...Don't forget to add any dependencies you added to you old project. Look at the package.json file of the old project and import all dependencies.
Hit the start command (npm start in my case) and see your project running.
*I'll update if I found some firebase secret to resolve this issue. You can look for the same.
Ensure your firebase project support email and firebase initialize login email are same. If different? It won't be worked. so you must ensure it that two email (firebase project support email and firebase initialize email) are same.

Path variables not working on 0.6.5 e.g. METEOR_SETTINGS

i cannot get it working after i updated to 0.6.5.
I created a new meteor project.
I have a start.sh script that looks like this.
export METEOR_SETTINGS=$(cat ./settings.json)
meteor
settings.json:
{
"public":{
"bla":"blup"
}
}
Meteor.settings on the client is undefined. It works if i add the settings json file via "--settings", but unfortunately this is not what i need.
The PORT environment variable or NODE_ENV also does not work for me.
Adding some random stuff like "export MY_ENV_VAR=foo" however works.
Am i missing s.th.? It all worked well before. I would really appreciate your help.
Thx!
(also created an issue: https://github.com/meteor/meteor/issues/1381)
If you are trying to test your meteor app locally (dev mode) or you want to deploy your app to the Meteor hosting, then just pass the file path as settings param:
meteor --settings settings.json
In case of running from bundle on your own server, then you need the environment variable.
Docs.

Resources