Remove default parameter of MDXContent component in compile output? #2484
-
Currently, the compile output contains the following: export default function MDXContent(props = {}) { This should not have a default parameter A type error occurs at
To address this, my build script includes the following: import { mkdir, readFile, writeFile } from "node:fs/promises";
import babel from "@babel/core";
import { dirname } from "node:path";
import { babelPluginSyntaxMdx } from "./plugin";
const original = `export default function MDXContent(props = {}) {
const {
wrapper: MDXLayout
} = props.components || {};
return MDXLayout ? _jsx(MDXLayout, {
...props,
children: _jsx(_createMdxContent, {
...props
})
}) : _createMdxContent(props);
}`;
const replacement = `export { _createMdxContent as default };`;
export async function compile(
inFilePath: string,
outFilePath: string
): Promise<void> {
const content = (await readFile(inFilePath)).toString();
const result = await babel.transformAsync(content, {
filename: inFilePath,
plugins: [babelPluginSyntaxMdx],
});
const code = result!.code!;
if (!code.endsWith(original)) {
throw new Error("Dependencies updated, build script must be updated.");
}
const replacedCode =
code.substring(0, code.length - original.length) + replacement;
await mkdir(dirname(outFilePath), { recursive: true });
await writeFile(outFilePath, replacedCode);
} So my question is: Is it worth opening an issue about this? I'm not sure if it is really a problem. Minimum reproducible example: https://github.com/my-trash-bin/240526 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Please elaborate where you’re seeing this error. To what file is it related? What command are you running? What is the exact output? Do you have an example repository and steps to reproduce? |
Beta Was this translation helpful? Give feedback.
They’re checking whether the inferred type satisfies
PageProps
. What matters is thatPageProps
is assignable to{} | undefined
.Anyway, I suggest to exclude
**/(articles)/**
from type checking. This is one quirks of an IMO quite hacky approach by Next.js. I feel more will follow. But you should use whatever solution you think is best.