Does this work in SPA mode??
Hello,
I am curious if this package works in SPA mode?
<template>
<div>
<h1>HELLO</h1>
<article>
<nuxt-content :document="doc" />
</article>
</div>
</template>
<script>
export default {
components: {
},
async asyncData({$content}) {
const doc = await $content('index').fetch();
return {doc}
}
}
</script>
This is my code, and somehow on my local machine this works....but I always thought asyncData only works for SSR Mode?
However, when I upload this to firebase hosting, it does not work anymore.
Trying to understand why.
Hi @limjix
The actual issue of nuxt build with spa mode is that it created a dist/ directory where actually it can be used with nuxt start and a server.
If you want to use the spa mode and a static hosting, you need to use nuxt generate instead of nuxt build, this way, Nuxt Content will know that it has to embed the database and avoid calling the server middleware.
With Nuxt 2.13, you will simply have to set target: 'static' in your nuxt.config.js.
@Atinux Why is there no documentation or "help" section on this? I have an app that has been SPA for over a year. I did all the "requirements" and got everything working in development... deployed to my app to my server to be hosted and get blasted with 404s with no clue in the world as to why.
Also it's not exactly feasible to just use a development version of nuxt or to use generate because other nuxt modules like i18n have problems with generate. Please provide a working example of how to use SPA please.
Well give a reproduction of what you are describing @jameshhood because it should work
@Atinux I just followed the installation steps of the document and left everything default. I added my content folder and some MD files and everything is fine in development. When I run a build and deploy to my server, it 404s. I've even tried copying my folder into the /dist folder but it didnt work. I guess I need to try /_content since thats the default, but why this doesn't work out of the box for SPAs and why there doesn't seem to be anything in the documentation about it is why I'm saying that there should be something in the documentation about it.
By copying the content folder to dist/_content I was able to get the 404s to go away, however, none of the content is rendering correctly. I have vue written in my markdown files and text and variables are working, but vue is not being compiled properly. Guessing this all has to deal with SPA...Since this really only works with static out of the box, there really needs to be examples or disclaimers on SSR and SPA usages.
I am seeing similar issues, except we are trying to build in universal / ssr mode. After we run nuxt build, we take the pre-compiled .nuxt folder and deploy it without the source code. This approach works, except when we add the nuxt/content module. We get an error like this:
ERROR inject('content', value) has no value provided 20:18:10
at inject (.nuxt/index.js:154:0)
at plugin_server (.nuxt/content/plugin.server.js:9:0)
at createApp (.nuxt/index.js:222:0)
Workaround is that we copy over the source folder (specifically our .md files), copy over the nuxt config, and then things work.
Seems like packaging of nuxt-content isn't really ready for a standalone package of ssr build, or am I wrong?
Since the markdownfiles are parsed at nuxt start you have to deploy the content folder. This is nice so when your content folder changes you only stop the nuxt start process and start it again.
@mathe42 Thanks for the answer. While I do get your point that this is better for content reloading, parsing files at nuxt start works against the idea that the project can be prepackaged with nuxt build
In our case, it adds several seconds to the startup time of the AWS lambda that runs the SSR instance. That just kills the ability to use AWS Lambda for the purpose.
I'm running server mode and encountering the same exception @MatejBalantic is encountering. nuxt-content works locally (nuxt start) but not when deployed to Vercel. Commenting out the @nuxt/content module in nuxt.config.js gets rid of the problem.
ERROR inject('content', value) has no value provided
at inject (.nuxt/index.js:149:0)
at plugin_server (.nuxt/content/plugin.server.js:9:0)
at createApp (.nuxt/index.js:209:0)
at async module.exports.__webpack_exports__.default (.nuxt/server.js:81:0)
I'm using Vercel. It looks like Vercel doesn't support nuxt/content: https://github.com/nuxt/vercel-builder/issues/328#issuecomment-682096222
Hi @MatejBalantic @seeARMS Have you got the solution now? I also experienced the same thing when I uploaded to a hosting service. However, if I turn off the @nuxt/content module everything works fine.
Hi @febrihidayan, our solution was to move away from nuxt/content and use markdown-it to load our MD files
Thanks @MatejBalantic, I seem to prefer to use marked
I know this has been a while but the bug is still prevalent, @MatejBalantic how did you go about swapping from nuxt content to markdown-it and will I have to but any changes in my current md files? thanks!
I am working to add support for serverless actually, to avoid scanning on Nuxt-start and improve the boot up time.
I personally switched to using Prismic. It's been great for what I need out of a CMS.
@seeARMS @MatejBalantic
We switched from static (generate) to SSR and had the same issue. With the config below we can load .md files in asyncData the usual way without a problem. The /_content/ API is available too.
{
"builds": [
{
"src": "nuxt.config.js",
"use": "@nuxtjs/vercel-builder",
"config": {
"serverFiles": [
".nuxt/content/**",
"content/**"
]
}
}
]
}
I am seeing similar issues, except we are trying to build in
universal/ssrmode. After we runnuxt build, we take the pre-compiled.nuxtfolder and deploy it without the source code. This approach works, except when we add thenuxt/contentmodule. We get an error like this:ERROR inject('content', value) has no value provided 20:18:10 at inject (.nuxt/index.js:154:0) at plugin_server (.nuxt/content/plugin.server.js:9:0) at createApp (.nuxt/index.js:222:0)Workaround is that we copy over the source folder (specifically our
.mdfiles), copy over the nuxt config, and then things work.Seems like packaging of nuxt-content isn't really ready for a standalone package of
ssrbuild, or am I wrong?
@MatejBalantic Sorry for digging out such an old topic, but how excactly did you solve this? I tried this but without a good result. Where did you copy your content folder at? /app/content /app/.nuxt/content /app/.nuxt/dist/client/content
It seems that content does not work with standalone mode :(
same problem in nuxt v3 and content v2 it seems. https://github.com/nuxt/content/issues/1154#issuecomment-1138766797
whenever I generate the SPA app - none of the markdown content gets copied:
export default defineNuxtConfig({
ssr: false, // Disable Server Side rendering
//...
})
i Prerendering 4 initial routes with crawler nitro 10:34:56
├─ / (13ms) nitro 10:34:56
├─ /200 (1ms) nitro 10:34:56
├─ /404 (1ms) nitro 10:34:56
├─ /api/_content/cache (66ms)
the result is that none of the pages could be queried nor viewed.. I was surprised to find this thread from 2020 and seeing that there is no proper fix yet.. or??
@Atinux seeing that it still causes trouble for people, do you have anything to comment or to add on the issue?
What's funny is I'm now migrating my project from nuxt/vue 2 to 3 and I'm running into this same issue almost 5 years later and I still cant get this to work with using nuxt/content 3. I just wanted to embed a simple changelog into my app but what I just did was add the markdown file in my public directory and use the markdown-it package to render the markdown. Still not super ideal but at least it works.