Open
Description
If vite is installed with preset-vite in a subdirectory of the project root and both node_modules folders has a preact-lib, there can be a mismatch in which preact-library it should use and we get:
Uncaught TypeError: Cannot read properties of undefined (reading '__H')
If the aliases in resolve.alias are set with full path the problem goes away. So a monkey patched version can look like this:
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'
import path from 'path';
const configPatch = () => ({
resolve: {
alias: {
'react-dom/test-utils': path.resolve(__dirname, './node_modules/preact/test-utils'),
'react-dom': path.resolve(__dirname, './node_modules/preact/compat'),
react: path.resolve(__dirname, './node_modules/preact/compat')
}
}
});
const preactPlugin = preact()
preactPlugin[0].config = configPatch;
export default defineConfig({
plugins: [preactPlugin],
})
So the alias needs to point to the react lib in the vite-folder. It would be great to have this is preact-vite instead of the patch above.
Metadata
Metadata
Assignees
Labels
No labels