Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nextra 4] Add a config param to ignore AppDir content #3990

Open
GuillaumeDSM opened this issue Jan 21, 2025 · 1 comment
Open

[Nextra 4] Add a config param to ignore AppDir content #3990

GuillaumeDSM opened this issue Jan 21, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@GuillaumeDSM
Copy link

GuillaumeDSM commented Jan 21, 2025

Hello!
First of all, thanks a lot for your great work with Nextra and the update to Nextra 4.

I'm currently updating to Nextra 4 and I have the following situation.
My existing Next.js AppDir website with a locales uses next-intl for localisation (https://github.com/amannn/next-intl) and is using many different types of .tsx pages, groups etc: (pages) [pages].
This was perfectly fine in Nextra 3 since nextra content was in /pages. I migrated the website to Nextra 4 using the Using Content Directory Convention and the issue is that my AppDir content (which deosn't contain any Nextra page) is crashing the PageMap function.

Right now, I have to patch the Nextra 4 code to force it to ignore AppDir content, this way it work.

=> Would it be possible to add an option in withNextra config param not to explore the AppDir content when Nextra content is set to use the Content Directory Convention please ?

Here is the patch I had to add:

diff --git a/dist/server/page-map/find-meta-and-page-file-paths.js b/dist/server/page-map/find-meta-and-page-file-paths.js
index e9bdc946c78e917d83de9584c04206d0c62a84a8..9cd9c92e88991e0a475f1eb19671b4445322ebe0 100644
--- a/dist/server/page-map/find-meta-and-page-file-paths.js
+++ b/dist/server/page-map/find-meta-and-page-file-paths.js
@@ -14,13 +14,15 @@ async function findMetaAndPageFilePaths({
     `${contentDir}/**/_meta.{js,jsx,ts,tsx}`,
     // Include `_meta` files from `content` directory
     `${contentDir}/**/*.{md,mdx}`,
-    // Include all Markdown/MDX files from `content` directory
-    `${appDir}/**/page.{js,jsx,jsx,tsx,md,mdx}`,
-    `${appDir}/**/_meta.{js,jsx,ts,tsx}`,
-    // Include `_meta` files from `app` directory
-    `${appDir}/_meta.global.{js,jsx,ts,tsx}`,
-    // Include global `_meta` file from `app` directory
-    `!${appDir}/**/{_,[}*/*`
+    // START LOCAL PATCH
+    // // Include all Markdown/MDX files from `content` directory
+    // `${appDir}/**/page.{js,jsx,jsx,tsx,md,mdx}`,
+    // `${appDir}/**/_meta.{js,jsx,ts,tsx}`,
+    // // Include `_meta` files from `app` directory
+    // `${appDir}/_meta.global.{js,jsx,ts,tsx}`,
+    // // Include global `_meta` file from `app` directory
+    // `!${appDir}/**/{_,[}*/*`
+    // END LOCAL PATCH
     // Ignore subdirectories starting with `_` and dynamic routes
   ] : ["**/_meta.{js,jsx,ts,tsx}", "**/*.{md,mdx}"];
   const result = await fg(pattern, { cwd });

And here is the error:

../../../node_modules/.pnpm/[email protected][email protected][email protected]_@[email protected][email protected][email protected]_tad3r3bwmk4rowd6m4b3glsev4/node_modules/nextra/dist/server/page-map/placeholder.js?lang=
Error: Can't find "page" file for:
{
  "path": "[locale]",
  "mdxPages": {
    "[locale]/account": "app/[locale]/(app)/account/page.tsx",
    "[locale]/account/settings": "app/[locale]/(app)/account/settings/page.tsx",
    "[locale]/account/subscription": "app/[locale]/(app)/account/subscription/page.tsx",

...

at Array.map (<anonymous>)
../../../node_modules/.pnpm/[email protected][email protected][email protected]_@[email protected][email protected][email protected]_tad3r3bwmk4rowd6m4b3glsev4/node_modules/nextra/dist/server/p../../../node_modules/.pnpm/[email protected][email protected][email protected]_@[email protected][email protected][email protected]_tad3r3bwmk4rowd6m4b3glsev4/node_modules/nextra/dist/server/page-map/placeholder.js?lang=
../../../node_modules/.pnpm/[email protected][email protected][email protected]_@[email protected][email protected][email protected]_tad3r3bwmk4rowd6m4b3glsev4/node_modules/nextra/dist/server/page-map/get.js
../../../node_modules/.pnpm/[email protected][email protected][email protected]_@[email protected][email protected][email protected]_tad3r3bwmk4rowd6m4b3glsev4/node_modules/nextra/dist/client/pages.js
./app/(nextra)/[locale]/blog/[[...mdxPath]]/page.tsx

@GuillaumeDSM GuillaumeDSM added the enhancement New feature or request label Jan 21, 2025
@dimaMachina
Copy link
Collaborator

Dynamic folders [something] should be ignored according this line

`!${appDir}/**/{_,[}*/*` // Ignore subdirectories starting with `_` and dynamic routes

could you add a failing test? and I will fix it

example of test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants