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

Extension doesn't resolve Nuxt 3 aliases #564

Open
4 tasks done
TheDutchCoder opened this issue Dec 18, 2024 · 2 comments
Open
4 tasks done

Extension doesn't resolve Nuxt 3 aliases #564

TheDutchCoder opened this issue Dec 18, 2024 · 2 comments

Comments

@TheDutchCoder
Copy link

TheDutchCoder commented Dec 18, 2024

Describe the bug

When running vitest through the extension, it will fail to resolve paths like ~/utils and other ones using ~, which is an alias that's available in Nuxt.

Running vitest in the CLI has no issues with this.

Manually adding aliasses to tsconfig or vitest's config have no effect.

Reproduction

https://github.com/TheDutchCoder/vitest-extension-bug

Output

Part of the output with the errors.

[Error 8:13:12 PM] Error in /Users/reinierkaper/rvezy/rvezy-web-client/src/utils/rv/get-rv-snapshot.vitest.spec.ts Error: Failed to load url ~/constants (resolved id: ~/constants) in /Users/reinierkaper/rvezy/rvezy-web-client/src/utils/rv/get-rv-details.ts. Does the file exist?
    at loadAndTransform (file:///Users/reinierkaper/rvezy/rvezy-web-client/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:51920:17)
    at async ViteNodeServer._transformRequest (file:///Users/reinierkaper/rvezy/rvezy-web-client/node_modules/vite-node/dist/server.mjs:542:16)
    at async ViteNodeServer._fetchModule (file:///Users/reinierkaper/rvezy/rvezy-web-client/node_modules/vite-node/dist/server.mjs:504:17)
    at async Proxy.fetch (file:///Users/reinierkaper/rvezy/rvezy-web-client/node_modules/vitest/dist/chunks/resolveConfig.RxKrDli4.js:6616:22)
    at async EventEmitter.onMessage (file:///Users/reinierkaper/rvezy/rvezy-web-client/node_modules/vitest/dist/chunks/index.68735LiX.js:91:20)

Extension Version

1.8.4

Vitest Version

2.1.8

Validations

Screenshots

Example of the extension failing
image

Example of CLI working just fine:
image

@TheDutchCoder
Copy link
Author

Additional info: the CLI version also doesn't work when ran from the root with vitest directly, only when fed the config file.
Is this an issue with vitest itself then?

@cmlima
Copy link

cmlima commented Jan 3, 2025

I encountered the same issue and resolved it by removing Vitest from the project folders and placing it only in the root of the monorepo. This made my workspace cleaner, and the VS Code extension started running all tests correctly. Additionally, because Vitest was not installed at the project level anymore, I was able to move all "test dependencies" to the root.

This is how my package.json in the root now looks like:

  "devDependencies": {
    "@cecalc/eslint-config": "workspace:*",
    "@nuxt/test-utils": "^3.15.1",
    "@turbo/gen": "^2.3.3",
    "@vitest/coverage-v8": "^2.1.8",
    "@vitest/ui": "2.1.8",
    "@vitest/web-worker": "2.1.8",
    "eslint": "^9.17.0",
    "happy-dom": "^15.0.0",
    "nuxt": "3.14.1592",
    "turbo": "^2.3.3",
    "typescript": "^5.7.2",
    "vite": "^5.0.0",
    "vitest": "^2.1.8",
    "vitest-environment-nuxt": "^1.0.1"
  }

I have no idea what happened, but it worked.

One more thing: I can still run tests locally through the CLI.

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

2 participants