Closed thomasledoux1 closed 1 year ago
Have you found any solution for this @thomasledoux1 ?
I have the same problem with mdx, but it works fine on Astro Example. Not sure what's making the issue here.
@surjithctly I didn't find it yet. The MDX blog which is giving the error during the build, works fine while working on the development server... I use the same MDX on another branch of my repo where I use the MDX as a page inside the /pages folder, and also works fine there. So it does seem to be caused by something which was added as part of the Collections RFC. Maybe @bholmesdev knows?
I'm also getting an error in development if I used mdx
in a parent folder with spaces. eg: My Works
.
Here's a related issue with the space in parent folder: https://github.com/withastro/astro/issues/5598
Thanks for sharing @thomasledoux1! Looks like an issue with escaping content of the MDX body. Can you send a minimal example on Stackblitz with the contents of adding-comments-prisma-planetscale-astro-vercel-edge.mdx
?
Also to clarify, is this an issue with spaces in the path to your project? This is being tracked separately as @surjithctly noted.
Hi @bholmesdev, thanks for getting back on this! The issue is not with spaces in the path of the project, I just checked that. Extra info: if I remove this specific MDX file, the build runs fine, while I do have a lot of other MDX files... Link to minimal example: https://stackblitz.com/edit/github-nabws4-nslpjk?file=src%2Flayouts%2FBlogLayout.astro,src%2Flayouts%2FLayout.astro,src%2Fpages%2Findex.mdx,src%2Fcomponents%2FFooter.astro,src%2Fcomponents%2FSocialLink.astro,src%2Fcomponents%2FNavigation.astro,src%2Fcomponents%2FNavigationItems.astro,package.json
Does this only happen with Content Collections or does it happen if the mdx file is just a normal page?
@matthewp only happens with Content Collections, as a normal page it works fine
@matthewp It's likely from the way we stringify the raw MDX body here. We do not expose the raw content in the regular MDX plugin. Maybe we need stronger serialization for MDX? https://github.com/withastro/astro/blob/main/packages/astro/src/content/vite-plugin-content-server.ts#L156
I'm confused, this Stackblitz doesn't use content collections. What am I missing @thomasledoux1 ?
@matthewp I just created a minimal reproduction with the MDX file in it as asked by @bholmesdev. If you want I can change the current Stackblitz, but I'm not sure if it's going to help a lot, since the error only occurs at build time? Not sure if you can run the build command in Stackblitz?
@thomasledoux1 I can pull it down and run the build locally. Just having something that breaks is super helpful, thank you!
Was able to reduce it down to being about the process.env.NODE_ENV
, so far:
```typescript
if (process.env.NODE_ENV === 'development') {
}
```
Will do some more investigation.
Not able to recreate with this example: https://stackblitz.com/edit/github-kbdjml?file=astro.config.mjs,src%2Fpages%2Findex.astro,src%2Fcontent%2Fconfig.ts,src%2Fcontent%2Fblog%2Fone.mdx&on=stackblitz
My assumption is there is something else with your config causing this.
My Astro.config.js looks like this if relevant:
import { defineConfig } from 'astro/config'; import tailwind from '@astrojs/tailwind'; import mdx from '@astrojs/mdx'; import { remarkReadingTime } from './src/utils/calculate-reading-time.mjs'; import vercel from '@astrojs/vercel/edge'; import react from '@astrojs/react'; import prefetch from '@astrojs/prefetch';
// https://astro.build/config export default defineConfig({ integrations: [ tailwind({ config: { applyBaseStyles: false, }, }), react(), mdx(), prefetch(), ], output: 'server', adapter: vercel(), markdown: { remarkPlugins: [remarkReadingTime], extendDefaultPlugins: true, }, site: 'https://www.thomasledoux.be', });
It's Vercel Edge that's causing it. Doesn't break with any other adapters:
Now going to see if mdx matters or not.
MDX does not matter. Also this is not related to content collections. Happens with a normal page too:
This workaround fixes it:
define: {
"process.env.NODE_ENV": `'${process.env.NODE_ENV}'`
}
In your astro.config file.
This is a bug in Vite, see https://github.com/vitejs/vite/issues/9829
Probably won't keep this issue open since it's an upstream issue. cc @bluwy. Let me know if you think there's a fix in Vite that's not too difficult. Another option is we set the above define
config in Astro although I'd prefer not to have to do that.
Confirmed that it's working now! Thanks a lot @matthewp for the thorough research! For others reading this, added the following in astro.config.js 's defineConfig():
vite: {
define: {
'process.env.NODE_ENV': `'${process.env.NODE_ENV}'`,
},
},
I was not using vercel adapter but this issue happened to me as well (static)
If this is not related to user config, it should be patched in Astro until vite fixes this.
While checking the workaround, I have nothing related to node.env in my code, so that’s strange I have to add that code.
Probably won't keep this issue open since it's an upstream issue. cc @bluwy. Let me know if you think there's a fix in Vite that's not too difficult. Another option is we set the above
define
config in Astro although I'd prefer not to have to do that.
There's two fixes in Vite - https://github.com/vitejs/vite/pull/9791 and https://github.com/vitejs/vite/pull/11151. Both have its own tradeoffs that aren't fully thought out yet, so I don't think it would be fixed soon. I agree that we should keep this as an upstream issue though since there's not much we can do.
I don't think the define
trick is a silver bullet too. It's assuming that the generated code uses double quotes, plus we shouldn't be replacing it in the first place so it's technically still undesired.
I'll close this one for now.
What version of
astro
are you using?1.8.0
Are you using an SSR adapter? If so, which one?
Vercel
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
When using a Collection with MDX files, and rendering a page for it as described in the docs, everything works as expected during development. When I try to build my site however, the build fails. I get the following error during build:
My astro.config.js:
I didn't add a Stackblitz reproduction, because it happens during build time, and not sure if that would be useful. I linked my Github repo instead, make sure the "use-prerender" branch is selected.
Link to Minimal Reproducible Example
https://github.com/thomasledoux1/website-thomas-astro/tree/feature/use-prerender
Participation