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.

Cannot resolve name `React` when using preact v8.3.1 with Flow v0.79.1

See original GitHub issue

I’m encountering the following issue when using flow with preact. I’ve followed your flow integration doc but it’s not working as expected.

Error

[flow] Cannot resolve name `React`. (view.js:36:5)
(property) JSX.IntrinsicElements.h1: JSX.HTMLAttributes
Flow-IDE
h1: (unknown)

Code (Shortened)

/* @flow */
'use strict';

import { h, Component } from 'preact';

type Props = {};

type State = {};

export class HelloWorld extends Component<Props, State> {
	constructor (props: Props) {
		super(props);
		this.state = { };
	}

	render (): any {
		return (
			<div class='hello-world'>
				<h1>Hello World</h1>  // This line fails
			</div>
		);
	}
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
bit2pixelcommented, Aug 26, 2018

Adding /** @jsx h */ manually to the top of each file seems to do the trick. More typing but at least it’s working.

2reactions
SerzN1commented, Dec 26, 2019

Think adding something to the top of each file, not the best approach. There is a better way at least for TS

https://github.com/preactjs/preact#default

For using Preact along with TypeScript add to tsconfig.json:

{ “jsx”: “react”, “jsxFactory”: “h”, }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot resolve name `React` when using preact v8.3.1 with ...
I'm encountering the following issue when using flow with preact. I've followed your flow integration doc but it's not working as expected.
Read more >
Switching to Preact (from React)
Switching to Preact can be as easy as installing and aliasing preact-compat in for react and react-dom . This lets you continue writing...
Read more >
Flow: Throws error Cannot resolve module "react-redux" even ...
How to fix it. You have two options: stub the dependency by hand; bring in flow-typed to find the dependency type file/stub it...
Read more >
preact-compat - npm
A React compatibility layer for Preact. Latest version: 3.19.0, last published: 3 years ago. Start using preact-compat in your project by ...
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