Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when used in an npm sub folder #56

Open
jschill opened this issue Sep 2, 2022 · 0 comments
Open

Error when used in an npm sub folder #56

jschill opened this issue Sep 2, 2022 · 0 comments

Comments

@jschill
Copy link

jschill commented Sep 2, 2022

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.

@jschill jschill changed the title Error when used in a sub module Error when used in a npm sub folder Sep 2, 2022
@jschill jschill changed the title Error when used in a npm sub folder Error when used in an npm sub folder Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant