fuma-nama / fumadocs

The beautiful docs framework with Next.js. Alternative to Nextra
https://fumadocs.vercel.app
MIT License
1.92k stars 117 forks source link

TypeError: index.mdx:TypeError: unsupported file type: undefined (file: undefined) #842

Closed thewilloftheshadow closed 2 months ago

thewilloftheshadow commented 2 months ago

To Reproduce

Sometimes, randomly, the build for the nextjs app that fumadocs is in completely fails with this error:

./content/carbon/index.mdx?collection=docs&hash=1d30f9ca6833ba4a9d23a2e59be4a0492e38327c0f064d1782befb73aa630964
TypeError: index.mdx:TypeError: unsupported file type: undefined (file: undefined)
    at lookup (/home/runner/work/carbon/carbon/node_modules/.pnpm/image-size@1.1.1/node_modules/image-size/dist/index.js:42:11)
    at imageSize (/home/runner/work/carbon/carbon/node_modules/.pnpm/image-size@1.1.1/node_modules/image-size/dist/index.js:98:16)
    at getImageSize (file:///home/runner/work/carbon/carbon/node_modules/.pnpm/fumadocs-core@13.4.5_@types+react@18.3.5_next@14.2.7_react-dom@18.3.1_react@18.3.1__react@18._agyctsxhd74ohvay7itkqbsntu/node_modules/fumadocs-core/dist/mdx-plugins/index.js:435:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Promise.all (index 1)
    at async file:///home/runner/work/carbon/carbon/node_modules/.pnpm/fumadocs-core@13.4.5_@types+react@18.3.5_next@14.2.7_react-dom@18.3.1_react@18.3.1__react@18._agyctsxhd74ohvay7itkqbsntu/node_modules/fumadocs-core/dist/mdx-plugins/index.js:402:5

Import trace for requested module:
./content/carbon/index.mdx?collection=docs&hash=1d30f9ca6833ba4a9d23a2e59be4a0492e38327c0f064d1782befb73aa630964
./.source/index.js
./app/source.ts
./app/[...slug]/page.tsx

> Build failed because of webpack errors
[MDX] writing manifest
cannot find the search index of /home/runner/work/carbon/carbon/website/content/carbon/index.mdx Error: ENOENT: no such file or directory, open '/home/runner/work/carbon/carbon/website/.next/cache/fumadocs/7501746fff48132fb226309435d15a66ffce61b92724c96c6e421b2aea1b3693.json'
    at Object.openSync (node:fs:561:18)
    at Object.readFileSync (node:fs:445:35)
    at writeManifest (file:///home/runner/work/carbon/carbon/node_modules/.pnpm/fumadocs-mdx@10.0.1_fumadocs-core@13.4.5_@types+react@18.3.5_next@14.2.7_react-dom@18.3.1_rea_hiw2hd4uosvn4ev5znz73d75te/node_modules/fumadocs-mdx/dist/chunk-P6WKCOD5.mjs:116:27)
    at process.<anonymous> (file:///home/runner/work/carbon/carbon/node_modules/.pnpm/fumadocs-mdx@10.0.1_fumadocs-core@13.4.5_@types+react@18.3.5_next@14.2.7_react-dom@18.3.1_rea_hiw2hd4uosvn4ev5znz73d75te/node_modules/fumadocs-mdx/dist/next/index.mjs:161:7)
    at process.emit (node:events:520:28)
    at process.exit (node:internal/process/per_thread:183:15)
    at printAndExit (/home/runner/work/carbon/carbon/node_modules/.pnpm/next@14.2.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/server/lib/utils.js:50:13)
    at /home/runner/work/carbon/carbon/node_modules/.pnpm/next@14.2.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/cli/next-build.js:58:37
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/runner/work/carbon/carbon/website/.next/cache/fumadocs/7501746fff48132fb226309435d15a66ffce61b92724c96c6e421b2aea1b3693.json'
}

This happens inconsistently, and rerunning the build works. I see it happen both in builds on GitHub actions and locally, and inconsistently so it's hard to track down. Figured I'd report it anyway

Current vs. Expected behavior

I expected it to built correctly like it usually does, but sometimes (like 1/10 times) it will fail

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103
  Available memory (MB): 8192
  Available CPU cores: 8
Binaries:
  Node: 22.6.0
  npm: 10.8.2
  Yarn: N/A
  pnpm: 9.9.0
Relevant Packages:
  next: 14.2.9 // Latest available version is detected (14.2.9).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 4.9.5
Next.js Config:
  output: export

Which area(s) are affected? (Select all that apply)

Core

Additional context

No response

fuma-nama commented 2 months ago

Did you reference any images in your document?

fuma-nama commented 2 months ago

We use image-size package to fetch image sizes, they have to be a valid image path/url. If you could provide a minimal production, I can help investigate the problem

thewilloftheshadow commented 2 months ago

Yes I do reference one image (external URL on our cdn: https://cdn.buape.com/CarbonWordmark.png) I'll try to get this to a reproduction repo tomorrow!

thewilloftheshadow commented 2 months ago

I haven't been able to reproduce this consistently isolated yet, but this is the file that it's erroring on (and the only image)

---
title: Introduction
index: true
icon: Album
---
![Wordmark](https://cdn.buape.com/CarbonWordmark.png)

Carbon is a powerful framework designed for building HTTP Discord bots.
fuma-nama commented 2 months ago

image

Failed to reproduce, you're also on MacOS so I don't think it's OS-related. Perhaps it's because of other usages? ![alt](image) will be recognized as an image.

fuma-nama commented 2 months ago

I think it's likely two reasons:

The plugin only fetches the image size when needed so it shouldn't happen unless there's problem fetching the image. If the problem consists, please consider using Next.js Image component in MDX file directly.