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

React is not defined: auto jsx runtime #58

Closed
samueljseay opened this issue Feb 6, 2022 · 23 comments
Closed

React is not defined: auto jsx runtime #58

samueljseay opened this issue Feb 6, 2022 · 23 comments

Comments

@samueljseay
Copy link

Hi, I depend on this package as a dependency of another npm package and I believe this issue: #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: developit/microbundle#763 (comment)

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! ✌🏻

@FezVrasta
Copy link
Owner

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

@samueljseay
Copy link
Author

I will thanks!

@samueljseay
Copy link
Author

@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.

@FezVrasta
Copy link
Owner

Could you please try 3.1.1-issue-58.1?

@FezVrasta
Copy link
Owner

@samueljseay ?

@FezVrasta
Copy link
Owner

@samueljseay may you please provide some feedback?

@johnnyomair
Copy link

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

@FezVrasta
Copy link
Owner

PRs are more than welcome 🙏

@johnnyomair
Copy link

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

johnnyomair added a commit to vivid-planet/comet that referenced this issue Nov 10, 2022
v3.1.2 introduces a `ReferenceError: jsx is not defined` error due to wrong configuration (see [issue](FezVrasta/react-resize-aware#58)). We therefore pin the version for the time being.
@johnnyomair
Copy link

PRs are more than welcome 🙏

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

@timothyallan
Copy link

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?

@DemiJiang33
Copy link

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

@samueljseay
Copy link
Author

@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.

@timothyallan
Copy link

@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.

@nickpell
Copy link

nickpell commented Dec 6, 2022

whats the issue with just sticking with 3.1.1?

3.1.1 does not support React 18 (see #59)

@Galkon
Copy link

Galkon commented Feb 10, 2023

Still getting this as of feb 2022

@Smef
Copy link

Smef commented May 10, 2023

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.

lewisl9029 added a commit to lewisl9029/highlight that referenced this issue Jul 12, 2023
3.1.2 seems to have a broken build that references jsx without importing react: FezVrasta/react-resize-aware#58
Vadman97 pushed a commit to highlight/highlight that referenced this issue Jul 13, 2023
## Summary

3.1.2 seems to have a broken build that references jsx without importing
react: FezVrasta/react-resize-aware#58

Pinning to the current version in the lockfile so there's no room for
deviation in Reflame deploys.

<!--
Ideally, there is an attached GitHub issue that will describe the "why".

If relevant, use this section to call out any additional information
you'd like to _highlight_ to the reviewer.
-->

## How did you test this change?

<!--
Frontend - Leave a screencast or a screenshot to visually describe the
changes.
-->

## Are there any deployment considerations?

<!--
 Backend - Do we need to consider migrations or backfilling data?
-->
@Crispae
Copy link

Crispae commented Aug 4, 2023

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

@FezVrasta
Copy link
Owner

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

samueljseay added a commit to woocommerce/woocommerce-blocks that referenced this issue Sep 1, 2023
samueljseay added a commit to woocommerce/woocommerce-blocks that referenced this issue Sep 5, 2023
* Fix bug where is-plain-obj is not transpiled by Jest, update lock.
* Update packages.
* Mock useSelect for a handful of RichText selectors in test.
* Resolve react to single version to avoid invalid hook errors.
* Patch trim-html locally to avoid a bug in the released npm source.
* Mock out resizeObserver to avoid FezVrasta/react-resize-aware#58
* Don't transpile config package: node-config/node-config#628
@andrewfritz86
Copy link

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 }])
);

@guipace
Copy link

guipace commented Mar 21, 2024

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

@FezVrasta
Copy link
Owner

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

@FezVrasta
Copy link
Owner

4.0.0 should address this problem

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