premieroctet / next-admin

▲ Full-featured admin for Next.js and Prisma
https://next-admin.js.org
MIT License
321 stars 19 forks source link

[BUG] - Error serializing `.locale` #452

Closed tevli closed 1 month ago

tevli commented 1 month ago

Description

On installing next-admin using the cli, it generates the necessary files but then throws this error on /admin route. Here is my pages/admin/[[...nextadmin]].tsx file:

`import { AdminComponentProps, NextAdmin } from "@premieroctet/next-admin"; import { getNextAdminProps } from "@premieroctet/next-admin/pageRouter"; import { GetServerSideProps, InferGetServerSidePropsType } from "next"; import prisma from "../../lib/prisma"; import schema from "../../../prisma/json-schema/json-schema.json"; import options from "../../../nextAdminOptions"; import "../../../nextAdminCss.css";

export default function Admin(props: InferGetServerSidePropsType) {

const { basePath, apiBasePath, ...restProps } = props;

return ( <NextAdmin basePath={basePath} apiBasePath={apiBasePath} options={options} {...restProps} /> ); }

export const getServerSideProps: GetServerSideProps = async ({ req }) => await getNextAdminProps({ basePath: "/admin", apiBasePath: "/api/admin", prisma, schema, options, req, locale: "en", });

`

On further investigation, it seems the locale is not being passed from node_modules\@premieroctet\next-admin\dist\pageRouter.js to getPropsFromParams in node_modules\@premieroctet\next-admin\dist\utils\props.js thereby leaving the locale undefined.

Reproduction URL

https://github.com

Reproduction steps

On installing next-admin using the cli, it generates the necessary files but then throws this error on /admin route. Here is my pages/admin/[[...nextadmin]].tsx file:

`import {  AdminComponentProps, NextAdmin } from "@premieroctet/next-admin";
import { getNextAdminProps } from "@premieroctet/next-admin/pageRouter";
import { GetServerSideProps, InferGetServerSidePropsType } from "next";
import prisma from "../../lib/prisma";
import schema from "../../../prisma/json-schema/json-schema.json";
import options from "../../../nextAdminOptions";
import "../../../nextAdminCss.css";

export default function Admin(props: InferGetServerSidePropsType<typeof getServerSideProps>) {

  const { basePath, apiBasePath, ...restProps } = props;

  return (
    <NextAdmin
      basePath={basePath}
      apiBasePath={apiBasePath}
      options={options}
      {...restProps}
    />
  );
}

export const getServerSideProps: GetServerSideProps = async ({ req }) =>
  await getNextAdminProps({
    basePath: "/admin",
    apiBasePath: "/api/admin",
    prisma,
    schema,
    options,
    req,
    locale: "en",
  });

`

On further investigation, it seems the locale is not being passed from node_modules\@premieroctet\next-admin\dist\pageRouter.js to getPropsFromParams in node_modules\@premieroctet\next-admin\dist\utils\props.js thereby leaving the locale undefined.

Next router

Page router

Next Admin version

6.1.2

Screenshots

![DESCRIPTION](LINK.png)

Next Admin options

import { NextAdminOptions } from "@premieroctet/next-admin";

export const options: NextAdminOptions = {
  title: "⚡️ My Admin Page",
  model: {
    /* Your model configuration here */
  },
  pages: {
    "/custom": {
      title: "Custom page",
      icon: "AdjustmentsHorizontalIcon",
    },
  },
  externalLinks: [
    {
      label: "App Router",
      url: "/",
    },
  ],
  sidebar: {
    groups: [
      {
        title: "Users",
        className: " bg-green-600 p-2 rounded-md", // group title extra classes. (optional)
        models: ["User"],
      },
      {
        title: "Transactions",
        models: ["Transactions"],
      },
    ],
  },
};

export default options;

Logs

Server Error
Error: Error serializing `.locale` returned from `getServerSideProps` in "/admin/[[...nextadmin]]".
Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.

This error happened while generating the page. Any console logs will be displayed in the terminal window.

Browsers

Chrome

foyarash commented 1 month ago

Hello @tevli

Thanks for the report, there was an issue with missing instructions about the installation of superjson, which is required for Page Router. This has now been added in CLI v0.0.3.

The locale issue has also been resolved in v6.1.3 of the lib