facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
227.44k stars 46.39k forks source link

[React 19]JSX asking that I should declare react at the top of the file #30704

Open jetro4u opened 1 month ago

jetro4u commented 1 month ago

Summary

Please I have a question. I am using React 19 canary version. It keeps asking that I should declare react at the top of the file and I know that was removed in v18 or so. Is it now a requirement or a bug?

Precisely the error says 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.ts(2686)

prayag2002 commented 1 month ago

If you're using React 19 canary and encountering an error that asks for the React import at the top of your files, it is likely related to TypeScript's configuration. React 18 introduced the automatic JSX runtime, eliminating the need to import React manually. Ensure your tsconfig.json has "jsx": "react-jsx" under compilerOptions. This is not a new requirement but a configuration issue. Adjusting your TypeScript settings should resolve the error. Feel free to correct.

eps1lon commented 1 month ago

Your build setup is using the classic JSX runtime that still requires a React import at the top.

It doesn't look like this bug report has enough info for one of us to reproduce it.

Please provide a CodeSandbox (https://react.new), or a link to a repository on GitHub.

Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve

jetro4u commented 1 month ago

If you're using React 19 canary and encountering an error that asks for the React import at the top of your files, it is likely related to TypeScript's configuration. React 18 introduced the automatic JSX runtime, eliminating the need to import React manually. Ensure your tsconfig.json has "jsx": "react-jsx" under compilerOptions. This is not a new requirement but a configuration issue. Adjusting your TypeScript settings should resolve the error. Feel free to correct.

I already did set '"jsx": "react-jsx"' and even tried "jsx": "preserve" before I ask the question