Skip to content

Error when used in an npm sub folder #56

Open
@jschill

Description

@jschill

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions