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

Vite Config TypeError on defineConfig regarding cacheDir with test config #26579

Closed
1 of 4 tasks
barrymichaeldoyle opened this issue Jun 17, 2024 · 3 comments
Closed
1 of 4 tasks
Assignees
Labels
scope: bundlers Issues related to webpack, rollup type: bug

Comments

@barrymichaeldoyle
Copy link
Contributor

Current Behavior

I get a type error if I specific a cacheDir in my test config:

export default defineConfig({
  test: {
    cacheDir: '../../../node_modules/.vitest/libs/shared/utils',
    ...
  },
  ...
})

Object literal may only specify known properties, and 'cacheDir' does not exist in type 'InlineConfig'.

What does work is this:

export default defineConfig({
  test: {
    cache: { dir: '../../../node_modules/.vitest/libs/shared/utils' },
    ...
  },
  ...
})

But when I do that and run the tests I get the following deprecation warning:

Vitest "cache.dir" is deprecated, use Vite's "cacheDir" instead if you want to change the cache director. Note caches will be written to "cacheDir/vitest"

Expected Behavior

Should not get type errors when using test.cacheDir. It's worth noting that everything works fine if I @ts-ignore. The tests run successfully and I do not get the deprecation warning mentioned above.

GitHub Repo

No response

Steps to Reproduce

  1. Set a test.cacheDir key in the defineConfgi in a vite.config.ts file.
  2. Get sad because you see type error.
  3. Get around it with an ugly @ts-ignore or @ts-expect-error.

Nx Report

Node   : 20.12.0
OS     : linux-arm64
bun    : 1.1.12

nx                 : 19.3.0
@nx/js             : 19.3.0
@nx/jest           : 19.3.0
@nx/linter         : 19.3.0
@nx/eslint         : 19.3.0
@nx/workspace      : 19.3.0
@nx/cypress        : 19.3.0
@nx/devkit         : 19.3.0
@nx/eslint-plugin  : 19.3.0
@nx/playwright     : 19.3.0
@nx/react          : 19.3.0
@nx/storybook      : 19.3.0
@nrwl/tao          : 19.3.0
@nx/vite           : 19.3.0
@nx/web            : 19.3.0
@nx/webpack        : 19.3.0
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/vite/plugin

Failure Logs

No overload matches this call.
  The last overload gave the following error.
    Object literal may only specify known properties, and 'cacheDir' does not exist in type 'InlineConfig'.ts(2769)
index.d.ts(3181, 18): The last overload is declared here.

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@Coly010 Coly010 self-assigned this Jun 26, 2024
@Coly010 Coly010 added the scope: bundlers Issues related to webpack, rollup label Jun 26, 2024
@Coly010
Copy link
Contributor

Coly010 commented Jun 28, 2024

Hey :) I think you've misunderstood where the cacheDir property is supposed to go.

cacheDir does not exist in the test object. You need to use the cacheDir at vite's object level.

defineConfig({
   cacheDir: "", // <---- Use it here!!
   test: {
       cacheDir: "" // <----- Not here!!
   }
})

@Coly010 Coly010 closed this as completed Jun 28, 2024
@Lonli-Lokli
Copy link

Lonli-Lokli commented Jun 28, 2024

@Coly010 Btw Nx now adds this cache dir to test too, as part of object, see https://github.com/Lonli-Lokli/issues-nrwl-nx-23303/blob/master/apps/nx-vitest/vite.config.ts#L37 (that's Nx sample for another issue #23303)

This property is deprecated, see vitest-dev/vitest#5229

@Coly010
Copy link
Contributor

Coly010 commented Jun 28, 2024

Yep, we can do some cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

No branches or pull requests

3 participants