react-resize-aware icon indicating copy to clipboard operation
react-resize-aware copied to clipboard

React is not defined: auto jsx runtime

Open samueljseay opened this issue 2 years ago • 20 comments

Hi, I depend on this package as a dependency of another npm package and I believe this issue: https://github.com/FezVrasta/react-resize-aware/issues/57 is seeing the same problem I see.

When I build with Vite with the auto jsx runtime available in React 17 I cannot use this package due to its microbundle distribution. and I get the error React is not defined.

I found that if I updated microbundle to latest and made an adjusted build for the jsx runtime, that I could use patch-package and still use this dependency.

The modified build command would be something like microbundle --name useResizeAware --jsx jsx --jsxImportSource react --globals react/jsx-runtime=jsx This was based on a suggestion here: https://github.com/developit/microbundle/issues/763#issuecomment-778848944

I was just wondering if you would consider releasing a package with support for the auto jsx runtime? At least for my situation turning off the auto JSX runtime is not an option I have right now. I would be happy to submit a PR with the build changes, but my only concern would be testing it for other environments.

Thanks! ✌🏻

samueljseay avatar Feb 06 '22 21:02 samueljseay

Thanks, could you please test it with [email protected]?

FezVrasta avatar Feb 07 '22 10:02 FezVrasta

I will thanks!

samueljseay avatar Feb 08 '22 02:02 samueljseay

@FezVrasta That doesn't work for me, I get jsx is undefined. But you're still using a very old version of microbundle, maybe thats the issue? In my version I updated microbundle to latest.

samueljseay avatar Feb 08 '22 02:02 samueljseay

Could you please try 3.1.1-issue-58.1?

FezVrasta avatar Feb 08 '22 10:02 FezVrasta

@samueljseay ?

FezVrasta avatar Mar 01 '22 14:03 FezVrasta

@samueljseay may you please provide some feedback?

FezVrasta avatar Mar 09 '22 13:03 FezVrasta

@FezVrasta it seems that v3.1.2 breaks applications using the old JSX transform. I'm getting the error ReferenceError: jsx is not defined

johnnyomair avatar Nov 08 '22 14:11 johnnyomair

PRs are more than welcome 🙏

FezVrasta avatar Nov 08 '22 14:11 FezVrasta

I believe it has something to do with setting --globals react/jsx-runtime=jsx.

johnnyomair avatar Nov 08 '22 14:11 johnnyomair

PRs are more than welcome 🙏

I'm sorry, we decided to use ResizeObserver instead. 🙃

johnnyomair avatar Nov 17 '22 16:11 johnnyomair

3.1.2 borked our entire app with ReferenceError: jsx is not defined as well. Are there any workarounds other than downgrading to 3.1.1 again?

timothyallan avatar Nov 21 '22 05:11 timothyallan

We also got the ReferenceError: jsx is not defined when using 3.1.2 😢

DemiJiang33 avatar Nov 21 '22 17:11 DemiJiang33

@timothyallan whats the issue with just sticking with 3.1.1? If you look at the releases, there are no functional changes that you need.

samueljseay avatar Nov 21 '22 20:11 samueljseay

@timothyallan whats the issue with just sticking with 3.1.1? If you look at the releases, there are no functional changes that you need.

Primarily because 3.1.2 is a bigger number than 3.1.1, therefore it must be better, and I want my package.json to have the biggest numbers in town for everything.

timothyallan avatar Nov 21 '22 20:11 timothyallan

whats the issue with just sticking with 3.1.1?

3.1.1 does not support React 18 (see https://github.com/FezVrasta/react-resize-aware/issues/59)

nickpell avatar Dec 06 '22 23:12 nickpell

Still getting this as of feb 2022

Galkon avatar Feb 10 '23 00:02 Galkon

This seems to be an issue still. 3.1.1 resolves this, but this is coming up deep in a dependency tree from some other packages we're using, and 3.1.2 is being installed by default, which makes it fail. I've manually installed 3.1.1 to override the one from the package we're using. I lost sooooo many hours trying to diagnose what was happening here.

Smef avatar May 10 '23 04:05 Smef

Hi, Do we have any solution to the issue "Uncaught ReferenceError: jsx is not defined". With NPM downgraded version is not available as well

Crispae avatar Aug 04 '23 11:08 Crispae

You can install the previous version that's compatible with the old jsx system.

FezVrasta avatar Aug 04 '23 11:08 FezVrasta

For those using jest and running into the JSX undefined issue, you can try simply mocking the hook:

jest.mock('react-resize-aware', () =>
  jest.fn().mockReturnValue([null, { width: 0 }])
);

andrewfritz86 avatar Jan 22 '24 20:01 andrewfritz86

Seems like v3.1.3 was released on npm yesterday, despite nothing here on GitHub. Has anyone given it a try to see if it solves this issue?

https://www.npmjs.com/package/react-resize-aware/v/3.1.3

guipace avatar Mar 21 '24 19:03 guipace

I haven't changed that in the last release. But I plan to work on it tomorrow.

FezVrasta avatar Mar 22 '24 00:03 FezVrasta

4.0.0 should address this problem

FezVrasta avatar Mar 22 '24 12:03 FezVrasta