davestewart / nuxt-content-assets

Enable locally-located assets in Nuxt Content

Home Page:https://npmjs.com/package/nuxt-content-assets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Small debugs

pv-g opened this issue ยท comments

Hi @davestewart,

Nice work and thanks for sharing, happy to try your module ;)

A first error I have :

 ERROR  Cannot restart nuxt:  Cannot read properties of undefined (reading 'ignores')                                                                                                                                                               11:34:14
  at node_modules/.pnpm/nuxt-content-assets@0.6.0_@nuxt+content@2.5.2/node_modules/nuxt-content-assets/dist/module.mjs:157:30
  at Array.forEach (<anonymous>)
  at node_modules/.pnpm/nuxt-content-assets@0.6.0_@nuxt+content@2.5.2/node_modules/nuxt-content-assets/dist/module.mjs:155:13
  at Array.forEach (<anonymous>)
  at setup (node_modules/.pnpm/nuxt-content-assets@0.6.0_@nuxt+content@2.5.2/node_modules/nuxt-content-assets/dist/module.mjs:152:19)
  at normalizedModule (node_modules/.pnpm/@nuxt+kit@3.3.3/node_modules/@nuxt/kit/dist/index.mjs:170:41)
  at async installModule (node_modules/.pnpm/@nuxt+kit@3.3.3/node_modules/@nuxt/kit/dist/index.mjs:452:15)
  at async initNuxt (node_modules/.pnpm/nuxt@3.3.3_hghbulspu73jfdazs4i6yiqype/node_modules/nuxt/dist/index.mjs:2477:7)
  at async load (node_modules/.pnpm/nuxi@3.3.3/node_modules/nuxi/dist/chunks/dev.mjs:6824:9)
  at async _applyPromised (node_modules/.pnpm/nuxi@3.3.3/node_modules/nuxi/dist/chunks/dev.mjs:6737:10)

I haven't set anything for content in my nuxt.config.ts, and my nuxt.options.content.ignores (in dist/module.mjs line 157) is undefined at nuxt start (maybe because @nuxt/content comes after?). Just setting an object there (e.g. content: {}) fixes it. But it should be safer to handle this case properly :)

Another one I see :

ERROR  RollupError: Could not resolve "../../config" from "node_modules/.pnpm/nuxt-content-assets@0.6.0_@nuxt+content@2.5.2/node_modules/nuxt-content-assets/dist/runtime/utils/debug.mjs"

Indeed, in dist/runtime/utils/debug.mjs, we have import { moduleKey } from "../../config" without a config file 2 levels above.

And when I manually fix this one, I get another one :

 ERROR  [worker reload] [worker init] defineNitroPlugin is not defined                                                                                                                                                                              12:22:06
  at .nuxt/dev/index.mjs:475:21
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
  at async loadESM (node:internal/process/esm_loader:88:5)
  at async handleMainPromise (node:internal/modules/run_main:61:12)

And the Nuxt server is not working.
But I don't know enough about how Nuxt works to fix that one ^^

Thanks again for the nice work.
Best,

Hey!

Thanks for taking the time to install the module and report back. Great info, thanks ๐Ÿ™

What version of the module do you have installed, BTW?

Sorry, latest one on NPM : 0.6.0
(with Nuxt 3.3.3)

OK! Pretty sure those will be fixed now.

Can you upgrade to v0.6.1 ?

Sure!

Yes, I confirm it clears the errors ;)

My images are not being displayed though, but that may be something else, I will check in details.

A thought on nuxt.options.content.ignores ||= [].
I am not sure wether it's safe or not because the content module's default is ['\\.', '-'] https://content.nuxtjs.org/api/configuration#ignores (and may change in the future).
Doesn't it clear the default and may have potentiel side effects?

As I understand it, that will set ignores only if it doesn't already exist:

var one = { ignores: [1, 2] }
var two = {}

one.ignores ||= []
two.ignores ||= []

console.log({ one, two })
{
  "one": {
    "ignores": [1, 2] // ignored
  },
  "two": {
    "ignores": [] // set
  }
}

I presume that they're using defu() somewhere to merge configs anyway?

My images are not being displayed though, but that may be something else, I will check in details.

Oh dear! Yes, do let me know. Obviously not a great first-run!

My point for nuxt.options.content.ignores ||= [] was within the context of Nuxt ;)

But I did some tests and :

  • If no ignores is specified in the config, even after the @nuxt/content module is loaded, nuxt.options.content.ignores is still undefined
  • Setting content.ignores to [] in the config don't actually remove the default patterns (['\\.', '-']) which are still active (the content module documentation is not clear about this mechanism). In other words, the configs are merged indeed.

...which means your instruction seem good in that case :)

And also, best for the end, my images are correctly being displayed eventually!

So looks good to me now, good work.
And I'll continue testing your module.

Best,

my images are correctly being displayed eventually!

Fantastic! Do you know what the problem was?

Is this something I can defend against or write documentation for?

I don't know what happened and cannot reproduce anymore, but if that happens again, I'll investigate and let you know.

You do need to manually restart the dev server each time the assets change.

I'm looking to solve this with a watcher at some point.

Did you run the build before adding the assets?

That's most probably the case!

I'm really looking forward to having the assets pop up as you add them!

Hopefully will find the time in the next week or so.

And, thanks again for helping me iron out the bugs "in production"! ๐Ÿ™ ๐Ÿ™Œ ๐Ÿป