Next.js Discord

Discord Forum

I keep getting this error: Error: msg.startsWith is not a function

Unanswered
Bull Arab posted this in #help-forum
Open in Discord
Bull ArabOP
I found an open source portfolio website on Vercel, and I'm trying to just see how it works. It does not provide much information besides the initial setup.

While I have been able to fix most of the errors myself (thanks to the helpful and informative error messages), this one I am struggling with. I keep on getting Error: msg.startsWith is not a function. I tried to search for msg.startsWith on the project directory and there's none at all.

It also says Next.js (13.4.8-canary.5) is outdated, and a "Learn more:" follows, which brings you to https://nextjs.org/docs/messages/version-staleness when clicked. I tried to do the possible ways to fix it according to the documentation, but got another error when use npm i next@canary.

21 Replies

Bull ArabOP
Update: I used pnpm add next@canary instead and that one worked fine. Even says that Next.js is up to date now. Still, I am getting the same error though.
Transvaal lion
How does the code in the above try block look like?
Bull ArabOP
Here goes:
import type { Metadata } from 'next';
import { auth } from 'lib/auth';
import { queryBuilder } from 'lib/planetscale';
import { SignIn, SignOut } from './buttons';
import Form from './form';

async function getGuestbook() {
  const data = await queryBuilder
    .selectFrom('guestbook')
    .select(['id', 'body', 'created_by', 'updated_at'])
    .orderBy('updated_at', 'desc')
    .limit(100)
    .execute();

  return data;
}

export const metadata: Metadata = {
  title: 'Guestbook',
  description: 'Sign my guestbook and leave your mark.',
};

export const dynamic = 'force-dynamic';
export const runtime = 'edge';

export default async function GuestbookPage() {
  let entries;
  let session;

  try {
    const [guestbookRes, sessionRes] = await Promise.allSettled([
      getGuestbook(),
      auth(),
    ]);

    if (guestbookRes.status === 'fulfilled' && guestbookRes.value[0]) {
      entries = guestbookRes.value;
    } else {
      console.error(guestbookRes);
    }

    if (sessionRes.status === 'fulfilled') {
      session = sessionRes.value;
    } else {
      console.error(sessionRes);
    }
  } catch (error) {
    console.error(error);
  }
I think that's a long-ass code. Sorry, coz I don't really know what we're looking at here.
But the bottom part, that's the line 48 that's written on the error.
Do you wanna see the error on console? Might provide more info
I can't really paste the whole text
I think it's got something to do with the database
Transvaal lion
Ah yeah, the database is not initialized it looks like
You don't have the neccesary database tables in place
Table 'blog.guestbook' doesn't exist
Is the repo open source?
Transvaal lion
Alright, you do have a planetscale database set up, right?
Bull ArabOP
Yep. I actually got the views on blog posts working. If anything, I just copied and pasted a code. Lol
Transvaal lion
Yeah, so you have a views table in that database?
You should probably create a new table named "guestbook" with the following fields
* id: Generated<number>;
* email: string;
* body: string;
* created_by: string;
* updated_at?: string;
Normally, you do this via migrations, see https://kysely-org.github.io/kysely/#migrations, but you can do it manually as well, migrations just keep it easier for others to clone the project and set it up. It also makes maintenance easier.. But for now - just create them manually.
Bull ArabOP
Can you check if this one is correct
CREATE TABLE guestbook (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) NOT NULL,
  body TEXT NOT NULL,
  created_by VARCHAR(255) NOT NULL,
  updated_at TIMESTAMP
);
I am still getting the same error:
But now without the part about the database.