#My .md collection breaks as soon as I add the MDX integration

37 messages · Page 1 of 1 (latest)

sharp dagger
#

Minimal example:
I create a new Astro project, and create a collection test, with a single (non-empty) .md file.
The complete contents of my index.astro are

---
import { getCollection } from 'astro:content';
await getCollection('test');
---

When I start the server and load this page, I get no error message.

Then I add the MDX integration using npx astro add mdx, and make no other changes. When I start the server and load the page again, I get the error
The collection "test" does not exist or is empty. Ensure a collection directory with this name exists.

What might be going on here?

(This is a continuation of my previous thread; I’m making a new thread for this since I have isolated the issue more and it feels somewhat distinct.)

meager oriole
#

I setup a test repo for this and I have no issues with it.

sharp dagger
#

That’s what I’d expect. If I’m experiencing this issue on my end, might it be a bug? I wanted to try uninstalling/reinstalling Astro but I wasn’t sure how to do that

meager oriole
#

Run an npx astro info

sharp dagger
#
Astro                    v4.15.12
Node                     v20.14.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx
meager oriole
#

That is super weird its having issues.

sharp dagger
#

Shall I put this minimal error repo on Git to see if you get errors on your end?

meager oriole
#

Yes Please

sharp dagger
meager oriole
#

Works just fine for me.

sharp dagger
#

Hmm. This made me wonder whether the issue was caused by the location where I had stored my project directory — there was a space in the pathname. I removed the space, and the issue went away. But this did not fix the issue I was encountering in my other thread.

meager oriole
#

Which issue got fixed?

sharp dagger
#

The “collection does not exist” error went away in this minimal test project. But not in the main project (which was also inside that same directory whose space I removed)

meager oriole
#

Try to move the main project into a new directory

sharp dagger
#

I moved it to my desktop but the issue still appears

meager oriole
#

Is that repo public?

sharp dagger
#

Yes, or at least an older version — if you’d like I can push the most recent version & send a link

meager oriole
#

Would be grat

#

Great

sharp dagger
#

Thank you! Give me a moment then

#

Here’s the link
(Excuse the messiness — as I described in the other thread, I was originally trying to finish this quickly while still learning a lot of the tools, so there is no typing and little documentation. But most of the files don’t really matter; I was able to reproduce the issue after deleting most of the files.)

GitHub

My portfolio website. Contribute to calder-rh/portfolio development by creating an account on GitHub.

meager oriole
#

So it is the mdx extension that is causing the issue. I confirmed that by checking this

const allWork = await getCollection('work');
console.log(allWork);

which returned []

So I changed one of the articles to .md and it loaded it just fine.

sharp dagger
#

Thank you for confirming the issue on your end. I had earlier done a similar test, where renaming an mdx file to md worked

#

Do you have any ideas about how to go about fixing this? I feel there must be some way to fix it since everything was working fine for me a few months ago

meager oriole
#

Let me see

#

You dont have the .mdx integration instaled

sharp dagger
#

Oh I might have pushed this after uninstalling mdx as part of a test. If you reinstall it and then run the server again, what happens?

#

(I get the same error whether or not it’s installed)

meager oriole
#

It works just fine for me

#

I would suggest rebooting your computer, maybe try to reinstall node?

#

Delete your node modules and reinstall

sharp dagger
#

I’ll try that — meaning, just the node_modules in this directory?

meager oriole
#

Yes.

#

Delete that and your package-lock.json

sharp dagger
#

However, for some reason, now I have reinstalled the MDX integration and the collections are showing up… I swear I tried that many times before, but it is working for some reason. At least partly. But if I can’t get it to work fully I will try that

meager oriole
#

Good deal