When @nuxt/content is added through a custom module, SPA mode and hot reloading of content fail
Version
@nuxt/content: 1.15.1 nuxt: 2.15.8
Reproduction Link
- SPA mode example: https://codesandbox.io/s/flamboyant-haibt-nc0qyh?file=/modules/example.js
- Universal mode example: https://codesandbox.io/s/solitary-currying-nc4brr?file=/modules/example.js
Steps to reproduce
- In the "SPA mode example", there is immediately a 404. If you check the console.log, you'll see a "Unexpected token < in JSON at position 0" error
- In the "Universal mode example", the initial response will look good, but if you edit a file from the "/content" directory, you'll get a fatal error
What is Expected?
To be able to use this.requireModule('@nuxt/content') from a module.
What is actually happening?
I'm encountering errors with SPA mode and hot reloading after content changes. When I add @nuxt/content to the nuxt.config.js modules array, no issues are encountered.
Hey @weotch ; I would suggest trying to add the @nuxt/content module to build.transpile array in this.options via your module.
Maybe before the requireModule call.
I like that suggestion, but it I'm still getting the same issue: https://codesandbox.io/s/vigilant-beaver-zzjt64?file=/modules/example.js
Hey :)
I managed to fix your reproduction there: https://stackblitz.com/edit/nuxt-starter-4grfyt
I changed two things there:
-
I'm using
nuxt-edge(2.16.0-27358576.777a4b7f) instead ofnuxtpackage. -
I'm pushing the
module.jsintobuildModulesinstead ofmodules.
Could you try one of these solutions and tell me the result?
I'm sure we'll find a solution, I've already used @nuxt/content that way in another project and it went quite well!
Hi @Tahul ,
I wanted to quickly add some documentation pages to an old application that I gave to customer long time ago. The nuxt content seemed to be simplest solution. But I couldn't fully understand how it works (with _slug) until I came across your example. I only added the subfolder and everything worked like a charm. Thank you very much for your post and example!