#Unhandled Runtime Error: Cannot use import statement outside a module

3 messages · Page 1 of 1 (latest)

wary nimbus
#

I'm using ContentLayer to made a MDX/React blog, but I'm getting this error. Below is the full code for that page. I've been stuck on this error for a while, so any help is appreciated. Thank you

sweet violetBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

wary nimbus
#
import { format, parseISO } from "date-fns";
import { allPosts } from "contentlayer/generated";
import Navbar from "@/app/navbar";
import { notFound } from "next/navigation";
import { Button } from "@/components/ui/button";
import { MDXComponents } from "mdx/types";
import { useMDXComponent } from "next-contentlayer/hooks";
import { useMDXComponents } from "mdx-components";
const mdxComponents: MDXComponents = { Button };
export const generateStaticParams = async () =>
    allPosts.map((post) => ({ slug: post._raw.flattenedPath }));
export const generateMetadata = ({ params }: { params: { slug: string } }) => {
    const post = allPosts.find((post) => post._raw.flattenedPath === params.slug);
    if (!post) throw new Error(`Post not found for slug: ${params.slug}`);
    return { title: post.title };
};
const PostLayout = ({ params }: { params: { slug: string } }) => {
    const post = allPosts.find((post) => post._raw.flattenedPath === params.slug);
    if (!post) {
        throw new Error(`Post not found for slug: ${params.slug}`);
        notFound();
    }
    const MDXContent = useMDXComponent(post.body.raw);```