question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parcel 2: Typescript + Preact

See original GitHub issue

🐛 bug report

Parcel remove unused Preact h in typescript (works with js):

Uncaught ReferenceError: h is not defined

💁 Possible Solution

looks like wrong jsxFactory detection, even if I add tsconfig.json with:

  "compilerOptions": {
    "jsx": "react",
    "jsxFactory": "h"
  },

I tried to investigate:

  • transformer-typescript-tsc doesn’t run by default, right?
  • but transformer-babel has jsx pragma logic should this work with the Typescript?

💻 Code Sample

// unused `h`
import { h, render } from "preact";

const App = () => <div>Hello world!</div>;

// works if uncomment:
// console.log(h);

const node = document.getElementById("root");

render(<App />, node!, node!.lastChild as Element);

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-alpha.1.1
Node v10.14.1
npm 6.10.3
Operating System macOS
preact 10.0.0-rc.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mischniccommented, Jan 28, 2020

@zackkrida I’m sorry, this is correct (babel’s typescript preset doesn’t react the tsconfig file):

{
	"presets": [["@babel/preset-typescript", {"jsxPragma": "h"}]]
}
0reactions
zackkridacommented, Dec 19, 2019

@mischnic The recommended configuration above does not work. I made a minimal a repro as possible here: https://github.com/zackkrida/play/tree/parcel2/ts-preact-issue

I have both the specified .babelrc

{
  "presets": ["@babel/preset-typescript"],
  "plugins": [["@babel/plugin-transform-react-jsx", { "pragma": "h" }]]
}

and tsconfig.json

{
  "compilerOptions": {
    "jsxFactory": "h",
    "jsx": "react"
  }
}

and still have the ReferenceError: h is not defined error. The “unused”, imported ‘h’ in my index.tsx file is still stripped out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple setup using Parcel, Preact, and TypeScript - GitHub
Minimal template using Parcel, Preact, and TypeScript. This template provides the simplest possible set-up that combines Parcel, Preact, TypeScript, and Jest.
Read more >
parcel-preact-typescript-boilerplate - npm
simple parcel2 preact typescript project without preact-compat. Latest version: 3.2.2, last published: a month ago.
Read more >
Preact Project with TypeScript and Parcel | Denys Vuika's Blog
In this article, I am going to walk you through the process of configuring a new web application project that is powered by...
Read more >
Recipes - Parcel
Preact. First we need to install the dependencies for Preact. npm install --save preact npm install --save-dev parcel-bundler.
Read more >
Switching to Preact (from React)
There are two different approaches to switch from React to Preact: ... Aliasing via Webpack; Aliasing via Parcel; Aliasing via Browserify; Aliasing Manually ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found