Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access RuntimeConfig via $config returns undefined #773

Open
marcel-wtfoxtrot opened this issue Mar 12, 2024 · 0 comments
Open

Access RuntimeConfig via $config returns undefined #773

marcel-wtfoxtrot opened this issue Mar 12, 2024 · 0 comments

Comments

@marcel-wtfoxtrot
Copy link

Environment


  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.9.3
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: devtools, runtimeConfig, modules
  • Runtime Modules: @nuxt/test-utils/module@3.11.0
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-j9nscj?file=vitest.config.ts

Describe the bug

Hi there,

during Migration i came across an issue. I still have some Options API Components which are using this.$config.public to access Nuxt Runtime Config.

It seems to be working fine but whenever i run vitest i receive the following error:

TypeError: Cannot read properties of undefined (reading 'public')

An simple Workaround for this is to simply mock $config globally.
But shouldn't $config be working out of the box?

Thank you!

Additional context

No response

Logs

TypeError: Cannot read properties of undefined (reading 'public')
 ❯ Proxy.data components/withPublicConfigAccess.vue:7:26
      8| </template>
      9| 
     10| <script>
       |      ^
     11| export default {
     12|   data() {
 ❯ applyOptions node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3460:30
 ❯ finishComponentSetup node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7663:7
 ❯ setupStatefulComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7586:5
 ❯ setupComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7515:36
 ❯ mountComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5845:7
 ❯ processComponent node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5811:9
 ❯ patch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5290:11
 ❯ ReactiveEffect.componentUpdateFn node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5955:11
 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:181:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant