Any idea how to use imports outside of a module? Trouble understanding this error:
What does this error mean by cannot use import statements outside a module? This is a mdx blog with contentlayer, and it doesn't like me using the
useMDXComponent
function.21 Replies
I'm not very well versed in how typescript works, so I'm having trouble figuring this out
if you could post your code inside a code tag like this, then it would be easier others to read and help you
I’ll do that rn
@sturlen
are you getting it?
I sent it in this thread
but i'm getting this message @sturlen
I don't see why you'd be blocked from posting here
specifically posting code weird
you might need to ask a mod then. I just answer the occasional question here
perfect thanks
had to cut a few lines empty lines
@machina0 did you add
withContentlayer
to your next config? https://contentlayer.dev/docs/reference/next-contentlayer-e6e7eb3a#withcontentlayerContentlayer
next-contentlayer – Contentlayer
Helper for improving the experience when developing with Next.js.
yeah here it is @sturlen
nothing strikes me as wrong at glance and the docs seem to agree. only idea I have is if something in the Button component is not working. have you tried importing in another component see if it works?
yeah let me try that
also does something seem wrong with the line
@sturlen
I've seen some tutorials use post.body.code there but I don't have a .code attribute in the body
it probably depends on which kind of content source you're using
hm should I open a github issue? @sturlen
oh theres a discord
according to the docs you should have access to the the code property on MDX https://contentlayer.dev/docs/sources/files/generated-types-fda1d801#provided-types
Contentlayer
Generated Type Definitions – Contentlayer
Contentlayer automatically generates type definitions for content that lives locally.
try running it in dev mode with
post.body.code
instead of raw
might also be related to using imports in the .mdx files
contentlayer does have it's own discord, they might have fix for this: https://discord.gg/rytFErsARmrunning it with code (with the red squiggle underneath) gives:
made another post for that too in the contentlayer discord. In the meantime I'll see if I can find a reason in the documentation