vitest: `Cannot destructure property 'AsymmetricMatcher'` with `deps.inline: true`

Describe the bug

I found that tests are broken after upgrading vitest from 0.27.1 to 0.28.4

% pnpm test

> test@ test /Users/alex/work/vitest-AsymmetricMatcher-issue
> vitest run --passWithNoTests


 RUN  v0.28.4 /Users/alex/work/vitest-AsymmetricMatcher-issue


 Test Files  no tests
      Tests  no tests
   Start at  15:04:47
   Duration  794ms (transform 242ms, setup 0ms, collect 0ms, tests 0ms)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: Cannot destructure property 'AsymmetricMatcher' of '__vite_ssr_import_0__.plugins' as it is undefined.
 ❯ node_modules/.pnpm/@vitest+utils@0.28.4/node_modules/@vitest/utils/dist/index.js:22:3
     20|   AsymmetricMatcher
     21| ];
     22| function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
       |   ^
     23|   const MAX_LENGTH = maxLength ?? 1e4;
     24|   let result;
 ❯ VitestRunner.directRequest node_modules/.pnpm/vite-node@0.28.4_@types+node@18.11.18/node_modules/vite-node/dist/client.mjs:312:5
 ❯ VitestRunner.cachedRequest node_modules/.pnpm/vite-node@0.28.4_@types+node@18.11.18/node_modules/vite-node/dist/client.mjs:156:14
 ❯ VitestRunner.dependencyRequest node_modules/.pnpm/vite-node@0.28.4_@types+node@18.11.18/node_modules/vite-node/dist/client.mjs:204:14
 ❯ async /Users/alex/work/vitest-AsymmetricMatcher-issue/node_modules/.pnpm/@vitest+runner@0.28.4/node_modules/@vitest/runner/dist/index.js:3:31
 ❯ VitestRunner.directRequest node_modules/.pnpm/vite-node@0.28.4_@types+node@18.11.18/node_modules/vite-node/dist/client.mjs:312:5
 ❯ VitestRunner.cachedRequest node_modules/.pnpm/vite-node@0.28.4_@types+node@18.11.18/node_modules/vite-node/dist/client.mjs:156:14
 ❯ VitestRunner.dependencyRequest node_modules/.pnpm/vite-node@0.28.4_@types+node@18.11.18/node_modules/vite-node/dist/client.mjs:204:14
 ❯ async /Users/alex/work/vitest-AsymmetricMatcher-issue/node_modules/.pnpm/vitest@0.28.4/node_modules/vitest/dist/entry.js:5:31
 ❯ VitestRunner.directRequest node_modules/.pnpm/vite-node@0.28.4_@types+node@18.11.18/node_modules/vite-node/dist/client.mjs:312:5

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
 ELIFECYCLE  Test failed. See above for more details.

The error is gone if I comment out the deps.inline setting: https://github.com/Leksat/vitest-AsymmetricMatcher-issue/blob/3d77d1d5e4b1e86f49e314234db835656388b0f6/vite.config.ts#L8

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-6a5vwn?file=vite.config.ts (I just added deps.inline: true to the standard example)

Or a minimal reproduction:

git clone git@github.com:Leksat/vitest-AsymmetricMatcher-issue.git
cd vitest-AsymmetricMatcher-issue
pnpm i
pnpm test

System Info

% npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers

  System:
    OS: macOS 13.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 110.18 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.0/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
  Browsers:
    Safari: 16.3
  npmPackages:
    vite: 4.1.1 => 4.1.1
    vitest: 0.28.4 => 0.28.4

Used Package Manager

pnpm

Validations

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 20
  • Comments: 21 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Found a workaround: inline everything except for vitest deps.

  {
    deps: {
      inline:
        // TODO: Replace with true once https://github.com/vitest-dev/vitest/issues/2806 is fixed.
        [/^(?!.*vitest).*$/],
    },
  },

I also have this issue when setting it to true, but using an array of packages to inline seems to work. I know that might not fit every use case, but it resolved my issue.

ex:

{
  deps: {
    inline: ['vuetify']
  }
}

Maybe this regex is too board and need to be narrowed down, but the smoking gun of this issue is here.

I disagree. It should not be needed to inline Vitest at all.

It should not be needed to inline any dependency to be honest. One of the reason why it takes so long to fix is because we will introduce another way to fix dependency issues and this usage of inline will probably be deprecated.

The fact that we allow true as a value was just to align with Vite‘s noExternal and should probably never be actually used. If you are using inline: true, you are shooting yourself in the foot.

Please, consider using deps.experimentalOptimizer instead of deps.inline.

deps.inline will be deprecated in future versions and will not be shipped in Vitest 1.0.

this needs to be fixed.

Actually, I just commented the whole inline out and it works.

  test: {
    // deps: {
    //   inline: true
    // }
  },

+1