-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
webpack should not warn import usage, when import is unreachable (e.g. guarded by if
statement)
#14814
Comments
guarding make sense, not sure that this will be implemented.. |
for now you can do something like:
but thats will bundle all |
In the absence of it, the warning shouldn't exist considering bundlers don't guard against any other missing property access. A type system is much better equipped to handle these issues.
That's generally not an issue since |
Hi there, Just to add, these two bugs will crash a Vercel setup. So hope that this bug can be resolved soon.
Thank you. |
Fix
Solves this. Are there any better ideas? Is webpack coming up with a patch? |
We will fix it, no need to duplicate, just wait |
Thank you, looking forward. |
Adding some further context on the Vercel breakage if it helps the team as well:
Cheers! And looking forward to the fix! Thank you! |
@sgrobert How did you make it crash with NextJS? Could you share a cloneable repository I can take a look at? Even with Workaround for library authors faced with the same issue: Instead of accessing potentially unavailable exports from a namespace import via static keys (e.g. |
Hi @eps1lon, I think this matter was previously resolved with the recent patch updates. Thank you for reaching out on this matter! ;) |
if
statement)
Any updates on when this will be fixed? We are running into this with our consumption of @radix-ui/react-tooltip. |
I've found that downstream bundlers have a tendency to remove the unnecessary string concatenation. It appears that |
Yeah, just make it non analyzable 😄 |
Bug report
What is the current behavior?
Bundling
will currently warn with
export 'useId' (imported as 'React') was not found in 'react'
(or crash ifstrictExportPresence
is enabled).If the current behavior is a bug, please provide the steps to reproduce.
yarn start:webpack
What is the expected behavior?
No warning in this case (just like Node.js and browsers with ES modules support. The repro repository has steps to verify the above code is safe in an ES module browser and Node.js).
We want to write code that works for both React 17 and React 18 (or rather provides improved behavior for React 18). However, this warning makes using the library very disruptive and even impossible if you have
strictExportPresence
enabled (like Create React App has): mui/material-ui#29860.The warning should probably apply to unconditional usage but in our case we have usage guarded with
Module.namedExport !== undefined
. This seems statically analyzeable and safe to disable the warning for every usage in that block).Other relevant information:
webpack version: npm:5.64.3
Node.js version: 16.13.0
Operating System: Ubuntu 20.04.3 LTS
Additional tools: Chrome Version 96.0.4664.45
The text was updated successfully, but these errors were encountered: