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

"Cannot find name 'h' with ts-loader" #78

Closed
tot-ra opened this issue Jan 4, 2023 · 1 comment
Closed

"Cannot find name 'h' with ts-loader" #78

tot-ra opened this issue Jan 4, 2023 · 1 comment

Comments

@tot-ra
Copy link

tot-ra commented Jan 4, 2023

Hey. I kept getting this error, related probably to preactjs/preact#3180 and https://github.com/preactjs-templates/typescript/blob/master/template/tsconfig.json#L8 lines..

After changing tsconfig to

  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "preact",
  }

the problem went away. Do you think it would be ok to update the template?

@rschristian
Copy link
Member

No, this is not a correct change to make.

Preact-CLI uses the classic JSX transform (in v3, this will change in v4) which means compiling to h() calls. As such, you should be importing h into every JSX/TSX file you have. However, as a convenience thing, we use Webpack's ProvidePlugin to inject h and Fragment imports into all modules automatically. Think of this as a poor man's runtime transform (and much older). This does not play nicely with TS though and there's no way around that.

Altering the tsconfig.json in this way is incorrect, as you're telling TS you're using the runtime transform (to avoid needing to import h) when in reality we're using the classic transform.

@rschristian rschristian closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2023
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

2 participants