It seems like the issue you're encountering is related to how Vite handles the manifest file during development and testing. When you run Vitest, it may be modifying or replacing the manifest.json file that Vite uses to resolve asset paths.
Here's a potential solution to your problem:
-
Ensure that Vitest is not modifying the
manifest.jsonfile used by Vite in development mode. You can do this by configuring Vitest to use a different output directory for its operations. Check yourvite.config.jsandvitest.config.js(or the relevant configuration sections in yourpackage.json) to make sure they are not conflicting. -
If you are using version control like Git, ensure that the
manifest.jsonfile is not being tracked or is restored to its original state after tests are run. -
You can also try to clear the Vite cache after running tests. This can be done by running the following command:
$ npm run dev -- --force
This will force Vite to regenerate the manifest and might resolve the issue.
- As a last resort, you can manually restore the
manifest.jsonfile after running tests. This is not an ideal solution, but it can serve as a temporary workaround.
If none of these solutions work, it might be helpful to look into the vitest and vite documentation or issues to see if there are any known conflicts or bugs related to the manifest file handling.
Remember to always back up your manifest.json or any other important files before making changes to your configuration or running commands that might modify them.