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

export "useId" was not found in "react" #82

Closed
jasonpaulmichel opened this issue Jan 12, 2023 · 14 comments · Fixed by #119
Closed

export "useId" was not found in "react" #82

jasonpaulmichel opened this issue Jan 12, 2023 · 14 comments · Fixed by #119

Comments

@jasonpaulmichel
Copy link

jasonpaulmichel commented Jan 12, 2023

Please note: This is related to Webpack issue: webpack/webpack#14814

Some bundles (Webpack) may throw an error during compilation if code references a named import that a module does not export– even if the import is only used conditionally.

The error thrown by Webpack will look like:

export 'useId' (imported as '$fpI56$useId') was not found in 'react'

To work around this, the following change was made in 0.0.38:

- const useReactId = (React as any).useId as () => string;
+ // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
+ const useReactId = (React as any)['useId'.toString()] as () => string;

Unfortunately it caused a regression and was reverted in 0.0.39. (Seemingly the new syntax confused Parcel.)


(Description modified by @bvaughn)

@bvaughn
Copy link
Owner

bvaughn commented Jan 12, 2023

Just a warning? Should be safe to ignore. It's coming from useUniqueId:

import { useId, useRef } from "react";
let counter = 0;
export default function useUniqueId(
idFromParams: string | null = null
): string {
const idFromUseId = typeof useId === "function" ? useId() : null;
const idRef = useRef<string | null>(idFromParams || idFromUseId || null);
if (idRef.current === null) {
idRef.current = "" + counter++;
}
return idRef.current;
}

@bvaughn bvaughn added the question Further information is requested label Jan 12, 2023
@jasonpaulmichel
Copy link
Author

Damn, thank you for the fast response!

@bvaughn
Copy link
Owner

bvaughn commented Jan 12, 2023

No prob! Sorry for the confusion.

@javiernievas
Copy link

I can confirm it raises an error on React v17. As it is trying to import useId and it does not exists.

ERROR in ./node_modules/react-resizable-panels/dist/react-resizable-panels.module.js 8:68-80
export 'useId' (imported as '$jhddX$useId') was not found in 'react'

@bvaughn
Copy link
Owner

bvaughn commented Feb 20, 2023

Can you share a repro for this? Same as I asked for with #104.

brightloudnoise added a commit to brightloudnoise/react-rezizable-panels-useid-repro that referenced this issue Apr 1, 2023
@brightloudnoise
Copy link

Here is a repro using CRA and React v17, and a possible work-around for webpack.

Thanks!

@bvaughn
Copy link
Owner

bvaughn commented Apr 1, 2023

@brightloudnoise Thanks for the work around pointer.

- const useReactId = (React as any).useId as () => string;
+ // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
+ const useReactId = (React as any)['useId'.toString()] as () => string;

That's some funky syntax!

I'm not opposed to adding it here, provided it doesn't break anything though.

@bvaughn bvaughn reopened this Apr 1, 2023
@bvaughn bvaughn removed the question Further information is requested label Apr 1, 2023
@bvaughn
Copy link
Owner

bvaughn commented Apr 1, 2023

Thinking about this a little more and I worry this might cause tree shaking issues. Admittedly the "react" package is pretty small and probably tree shaking it (or not) would have minimal impact on the bundle size.

Ideally though, this would be something that Webpack supports: (webpack/webpack#14814)

Maybe it's okay to make this change on our side in the meanwhile.

@bvaughn
Copy link
Owner

bvaughn commented Apr 1, 2023

Closed via ed96947

@bvaughn bvaughn closed this as completed Apr 1, 2023
@bvaughn
Copy link
Owner

bvaughn commented Apr 2, 2023

Fixed in 0.0.38

@bvaughn
Copy link
Owner

bvaughn commented Apr 2, 2023

Looks like this change caused a regression (#118) so I'm going to revert it in 0.0.39 for now (4b73ea5).

@bvaughn bvaughn reopened this Apr 2, 2023
@bvaughn bvaughn changed the title export 'useId' (imported as '$fpI56$useId') was not found in 'react' export "useId" was not found in "react" Apr 2, 2023
@bvaughn
Copy link
Owner

bvaughn commented Apr 2, 2023

Should be fixed in 0.0.39

@brightloudnoise
Copy link

Thanks for the fixes, and sorry the workaround caused other headaches.

@bvaughn
Copy link
Owner

bvaughn commented Apr 2, 2023

No worries 😄

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

Successfully merging a pull request may close this issue.

4 participants