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

ERR_UNSUPPORTED_DIR_IMPORT when using MDXContent or useMDXComponent #277

Closed
rossmeissl opened this issue Aug 30, 2024 · 16 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@rossmeissl
Copy link
Contributor

image

If I use mdx-bundler's getMDXComponent mechanism directly, the problem goes away.

@sdorra sdorra self-assigned this Aug 30, 2024
@sdorra sdorra added the bug Something isn't working label Aug 30, 2024
@sdorra
Copy link
Owner

sdorra commented Aug 30, 2024

Could you provide more details? Which package manager do you use? Is your application a module (type=module in package.json) or a commonjs app? Do you use the MDX hook or component in an RSC context? Can you show the code which uses the MDX hook or component?

@rossmeissl
Copy link
Contributor Author

@sdorra I could have sworn I responded here a few minutes ago but now it's gone. Did you remove the comment?

@sdorra
Copy link
Owner

sdorra commented Sep 3, 2024

@rossmeissl No, I am looking at the ticket for the first time today

@rossmeissl
Copy link
Contributor Author

@sdorra OK strange let me try again:

  • npm
  • Next.js 14.2.5
  • There's no type=module in package.json but I also don't think it's fair to say it's a CommonJS application
  • Here's a screenshot of the implementation against mdx-bundler which is almost the same as yours, but it works correctly. (I tried both the component and hook.)
image

@sdorra
Copy link
Owner

sdorra commented Sep 4, 2024

I've tried to reproduce the issue:

https://github.com/sdorra/cc-issue-277

But it works as expected. Can you check if there are any differences between my sample and yours?

@rossmeissl
Copy link
Contributor Author

My directory structure uses src/pages instead of /app . . . could that be it?

@sdorra
Copy link
Owner

sdorra commented Sep 4, 2024

@rossmeissl I've updated the sample to use the pages router with a src directory, and it works as well. Is it possible that I get access to the repository with the issue so that I can look myself?

@rossmeissl
Copy link
Contributor Author

Unfortunately no it's our monorepo but let me see if I can extract just enough to repro . . .

@rossmeissl
Copy link
Contributor Author

@sdorra sent you an email. Let me know if I can help further!

@sdorra
Copy link
Owner

sdorra commented Sep 5, 2024

@rossmeissl i was able to reproduce the issue. I can even reproduce it with my repository. When I navigate to an article and then press refresh, I get the error. The error seems to occur only in the Pages Router. I will try to fix it.

sdorra added a commit that referenced this issue Sep 5, 2024
Use full path to mdx-bundler client include index.js,
instead of only the directory.
This should fix the usage of mdx package in next.js pages router.

Closes: #277
@rossmeissl
Copy link
Contributor Author

Thanks @sdorra !

@sdorra
Copy link
Owner

sdorra commented Sep 6, 2024

@rossmeissl the fix is not yet released. Have you tested the fix with the preview release? If not can you please test if it fixes your problem? You only have to install the packages as described in the following comment:

#291 (comment)

@rossmeissl
Copy link
Contributor Author

Unfortunately I think it still doesn't work. I updated @content-collections/mdx in my package.json as follows:

{
  // ...
  "devDependencies": {
    "@content-collections/core": "^0.6.2",
    "@content-collections/mdx": "https://pkg.pr.new/sdorra/content-collections/@content-collections/mdx@291",
    // ...
  }
  // ...
}

And I get:

image

@rossmeissl rossmeissl reopened this Sep 9, 2024
@rossmeissl
Copy link
Contributor Author

Actually, hmm, this appears to have just emerged unrelated to this PR

@rossmeissl
Copy link
Contributor Author

It works!

(I had previously told Next to transpile mdx-bundler and content-collections/mdx in an attempt to fix this earlier and forgot to remove that bit.)

@rossmeissl
Copy link
Contributor Author

@sdorra shall I close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants