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

False positive on circular dependency check #3398

Closed
6 tasks done
silverbackdan opened this issue May 17, 2023 · 2 comments
Closed
6 tasks done

False positive on circular dependency check #3398

silverbackdan opened this issue May 17, 2023 · 2 comments

Comments

@silverbackdan
Copy link

Describe the bug

I have a very interesting setup but unfortunately seems needed and it works in my application.

I need to define a page in a nuxt app, that has to have a layout, and then in this layout I read a variable from a global store to find out which layout is needed dynamically, and then use the NuxtLayout component again but with a prop defining the name. This causes a circular dependency for tests, but it is not actually circular.

I think there could be better checks or a way to define a circular limit counter before throwing the error.

The Error I get is:

Error: [vite-node] Failed to resolve circular dependency, stack:
- virtual:nuxt:/Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/.nuxt/layouts.mjs
- /Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/node_modules/.pnpm/nuxt@3.5.0_@types+node@20.1.7_eslint@8.31.0_rollup@3.22.0_sass@1.62.1_typescript@5.0.4/node_modules/nuxt/dist/app/components/layout.js
- /Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/src/layer/layouts/cwa-root-layout.vue
- virtual:nuxt:/Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/.nuxt/layouts.mjs
- /Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/node_modules/.pnpm/nuxt@3.5.0_@types+node@20.1.7_eslint@8.31.0_rollup@3.22.0_sass@1.62.1_typescript@5.0.4/node_modules/nuxt/dist/pages/runtime/plugins/prefetch.client.js
- virtual:nuxt:/Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/.nuxt/plugins/client.mjs
- /Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/node_modules/.pnpm/nuxt@3.5.0_@types+node@20.1.7_eslint@8.31.0_rollup@3.22.0_sass@1.62.1_typescript@5.0.4/node_modules/nuxt/dist/app/entry.js
- /Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/node_modules/.pnpm/vitest-environment-nuxt@0.7.0_rollup@3.22.0_vitest@0.30.1_vue-router@4.2.0_vue@3.3.2/node_modules/vitest-environment-nuxt/dist/index.mjs

And although - virtual:nuxt:/Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/.nuxt/layouts.mjs is hit again, the next dependency would NOT be /Users/danielwest/Documents/GitHub/_CWA/cwa-nuxt-3-module/src/layer/layouts/cwa-root-layout.vue due to the prop being passed to it.

The check is performed here:
https://github.com/vitest-dev/vitest/blob/main/packages/vite-node/src/client.ts#L196

Reproduction

Root layout configured to be loaded from the Nuxt page

<template>
  <NuxtLayout :name="layoutName">
    <slot />
  </NuxtLayout>
</template>

<script setup>
import { computed } from 'vue'
import { useCwa } from '#imports'

const $cwa = useCwa()
const layoutName = computed(() => {
  const layoutResource = $cwa.resources.layout.value
  return layoutResource?.data?.uiComponent || 'cwa-default'
})
</script>

And the default layout passed if the other is unavailable

<template>
  <div>
    <slot />
  </div>
</template>

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 72.61 MB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.16.0 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/.npm-packages/bin/yarn
    npm: 8.11.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 113.0.5672.126
    Safari: 16.0
  npmPackages:
    @vitest/coverage-c8: ^0.30.0 => 0.30.0 
    vitest: 0.30.1 => 0.30.1

Used Package Manager

pnpm

Validations

@silverbackdan
Copy link
Author

Fixed in 0.31.1

@sheremet-va
Copy link
Member

sheremet-va commented May 17, 2023

I would assume it was fixed by #3196 in 0.31.0

@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants