preactjs / preact-compat

ATTENTION: The React compatibility layer for Preact has moved to the main preact repo.
http://npm.im/preact-compat
MIT License
950 stars 148 forks source link

Uncaught ReferenceError: h is not defined #541

Closed rzschoch closed 3 years ago

rzschoch commented 4 years ago

I try to omit the h imports for all my components while using a webpack/babel build process.

Following the preact documentation (https://preactjs.com/guide/v10/getting-started#integrating-into-an-existing-pipeline) for using preact with webpack I get this error: Uncaught ReferenceError: h is not defined.

An old issue (https://github.com/preactjs/preact-compat/issues/161) mentions this solution that is also working for me:

new webpack.ProvidePlugin({
  h: ['preact', 'h'],
})

Is there now a nicer solution to this problem?

developit commented 3 years ago

You can use the new automatic JSX runtime if you want to omit imports:

// babel config
["@babel/plugin-transform-react-jsx"], {
  "runtime": "automatic",
  "importSource": "preact"
}]