Skip to content

Demo of the root cause behind the Vitest >=1.0.0-beta.5 config.base browser test error

License

Notifications You must be signed in to change notification settings

mbland/vitest-utils-browser-import

Repository files navigation

Vitest >=1.0.0-beta.5 config.base browser test error demo

Using Vitest 1.0.0-beta.5 or later (including v1.0.1) when vite.config.js defines base produces the following error when running browser tests:

TypeError: Failed to fetch dynamically imported module: http://localhost:5173/@id/vitest/utils
This error originated in "demo.test.js" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.

This demo repo helped me determine the root cause:

This issue was filed just before I got the chance, so I'll attach my info there:

Reproduction steps

These are distilled from the steps recorded in the commit messages of this repo.

Initial setup for last good combination

Clone all these repos in the same directory:

git clone https://github.com/mbland/vitest-utils-browser-import.git
git clone https://github.com/vitejs/vite.git
git clone https://github.com/vitest-dev/vitest.git

Restore Vite and Vitest to the last versions that worked together without producing this error:

cd vite
git reset --hard v5.0.0-beta.7

# Not needed the first time, but for each rebuild:
rm -rf node_modules packages/*/node_modules

pnpm i --ignore-scripts --frozen-lockfile
pnpm build

cd ../vitest
git reset --hard v1.0.0-beta.4

# Same as above:
rm -rf node_modules packages/*/node_modules

pnpm i --ignore-scripts --frozen-lockfile
pnpm build

cd ../vitest-utils-browser-import
pnpm i --ignore-scripts
pnpm test

This should allow the Vitest UI to run and for the test (which does nothing but return null) to pass.

Setup failure with Vite commit

To reproduce the error, follow the same steps as above for the first Vite build:

cd ../vite
git reset --hard 40fd2d9bf4073420e6c334f48dc3b63558b688ce
rm -rf node_modules packages/*/node_modules
pnpm i --ignore-scripts --frozen-lockfile
pnpm build

cd ../vitest-utils-browser-import
pnpm i --ignore-scripts
pnpm test

This should produce the same failure as above.

Workaround

The workaround is to delete the config.base value in vitest.config.js. A version of this is already encoded here:

pnpm test:workaround

About

Demo of the root cause behind the Vitest >=1.0.0-beta.5 config.base browser test error

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published