vitest-dev / vitest-dev/vitest

The above dynamic import cannot be analyzed by Vite

Open
#11,293 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Describe the bug

14:19:58 [vite] (client) warning:
XXX/.angular/cache/22.1.8/frontend/vitest/9ecc8459ea5f39f9da55cb4d71a70b5d1e0f0b80/deps/vitest_n_vite_module-runner.js
814 | }
815 | runExternalModule(filepath) {
816 | return import(filepath);
| ^^^^^^^^
817 | }
818 | };
The above dynamic import cannot be analyzed by Vite.
See https://vite.dev/guide/features#dynamic-import for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

Reproduction

When I run the tests in the latest versions, I get a warning that doesn't affect anything.

My vitest setup

import { afterEach, beforeEach, vi } from 'vitest';
import { TestBed } from '@angular/core/testing';

// mocks for sanitize-html lib
(globalThis as any).process = { env: {}, cwd: () => '/' };

beforeEach(() => {
  vi.useFakeTimers();
});

afterEach(() => {
  vi.restoreAllMocks();
  vi.clearAllTimers();
  vi.useRealTimers();
  TestBed.resetTestingModule();
});
import { defineConfig } from 'vitest/config';
import path from 'path';

export default defineConfig({
  resolve: {
    alias: { // mocks for sanitize-html lib
      fs: path.resolve('./src/vitest-mocks/fs.ts'),
      path: path.resolve('./src/vitest-mocks/path.ts'),
      qs: path.resolve('./src/vitest-mocks/qs.ts'),
      url: path.resolve('./src/vitest-mocks/url.ts')
    }
  },
  optimizeDeps: {
    exclude: ['worker_threads']
  },
  test: {
    setupFiles: ['./src/vitest.setup.ts'],
    fileParallelism: true,
    pool: 'threads',
    hookTimeout: 15000,
    retry: 1
  }
});

I'll say it again: this doesn't affect performance at all. It's just visually distracting. That said, I don't want to disable the additional dependency checks, since I want to be sure that all modules are working properly. If you think this is important, perhaps you could offer some recommendations or fixes; if not, just close this

System Info
System:
    OS: Linux 7.0 Ubuntu 26.04.1 LTS 26.04.1 LTS (Resolute Raccoon)
    CPU: (24) x64 Intel(R) Core(TM) i7-14650HX
    Memory: 12.62 GB / 30.55 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 26.8.2 - /usr/bin/node
    npm: 11.19.1 - /usr/bin/npm
    pnpm: 12.4.2 - /usr/bin/pnpm
  Browsers:
    Chrome: 153.0.8010.47
    Chromium: 153.0.8010.36
    Firefox: 156.0
    Firefox Developer Edition: 156.0
  npmPackages:
    @vitest/browser-playwright: 5.0.1 => 5.0.1 
    @vitest/coverage-v8: 5.0.1 => 5.0.1 
    @vitest/expect: 5.0.1 => 5.0.1 
    vite: 8.3.0 => 8.3.0 
    vitest: 5.0.1 => 5.0.1
Used Package Manager

pnpm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Vitest configuration and setup file, then reproduce the warning and inspect the generated deps/vitest_n_vite_module-runner.js around line 816. Trace why Vite analyzes this dynamic import and verify that the warning can be addressed without disabling dependency checks, while the tests continue to pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
devtools, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.