Skip to content
Advertisement

Cannot find module ‘react’ when use third party React UI lib – Vite + Preact

I’m facing this issue in this Vite started repository.

https://github.com/vicainelli/vite-starter

I’m using Vite + Preact + Vitest + Testing Library

If I’m testing any code inside the codebase, it works fine, but If the test runs against some component that uses another component from an external library, I’m getting this error.

JavaScript

This is something similar to this issue, but I’m already using preact/compact, so, I have no idea what I’m doing wrong.

Advertisement

Answer

You’ll want to run the following:

JavaScript

Seems like Vitest cannot effectively alias.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement