content icon indicating copy to clipboard operation
content copied to clipboard

When @nuxt/content is added through a custom module, SPA mode and hot reloading of content fail

Open weotch opened this issue 4 years ago • 3 comments

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.

weotch avatar Apr 04 '22 23:04 weotch

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.

Tahul avatar May 09 '22 13:05 Tahul

I like that suggestion, but it I'm still getting the same issue: https://codesandbox.io/s/vigilant-beaver-zzjt64?file=/modules/example.js

weotch avatar May 09 '22 15:05 weotch

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 of nuxt package.

  • I'm pushing the module.js into buildModules instead of modules.

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!

Tahul avatar May 09 '22 23:05 Tahul

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!

klukiyan avatar Jan 10 '23 14:01 klukiyan