Throws Error about accessing `preference` of `undefined`
chrisspiegl opened this issue · 4 comments
Version
See Reproduction
Reproduction Link
Steps to reproduce
Running Vitest in a Package that uses @nuxtjs/color-mode
throws error upon initialization.
It is enough to have @nuxtjs/color-mode
in the nuxt.config.js
file without accessing the useColorMode()
anywhere in code.
Running pnpm vitest
in the reproduction throws:
[nuxt] error caught during app initialization TypeError: Cannot read properties of undefined (reading 'preference')
What is Expected?
Vitest should run without throwing any error.
What is actually happening?
Running Vitest throws an error as described above when @nuxtjs/color-mode
is present as a module in nuxt.config.js
.
Came up with this error today, I disabled the module for now.
Ran into this issue today with Nuxt 3.8; seems the last working version is Nuxt 3.6
EDIT:
Seems service workers are somehow interfering with this. I tried downgrading to v.3.2.0, and running in incognito, and it works fine there.
Disabled service workers on localhost:3000, and app runs fine.
Also, install in modules, rather than plugins.
export default defineNuxtConfig({
devtools: { enabled: true },
modules: [
"@nuxtjs/color-mode"
]
})
In my environment, v3.3.1 resolved the issue.
I now also ran my code with vitest and the latest versions of both @nuxt/test-utils
, vitest
, and @nuxtjs/color-mode
at 3.3.2
.