-
Notifications
You must be signed in to change notification settings - Fork 93
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
Duplicate declaration "React" #31
Comments
I don't think this plugin should include this behavior, it's totally unexpected and duplicates what the above mentioned plugin does. |
It only duplicates what the above plugin does if you're using babel-plugin-react-require, which Airbnb isn't, for example. Since this plugin actually checks to see if you have a React binding before adding the import, it seems like Specifically, https://github.com/vslinko/babel-plugin-react-require/blob/90f9994d936d85ad1b713afcfa256cb88d2b62e2/src/index.js#L14-L16 seems to suggest that it only adds the React binding when there is either no JSX, or a preexisting React binding - that logic should be changed to return early when there is a React binding present, regardless of whether jsx is present or not. |
Also getting this error in Next.js after upgrading to 0.5.1
|
@mitchellhuang what's your babel config that uses this plugin? |
.babelrc
next.config.js
|
What happens if you re-order your config so "presets" comes before "plugins"? |
@ljharb I'm also using next.js like @huangbong and I still get the same error if I move "presets" before "plugins" in my |
I downgraded to v0.4.0 and this solved the problem. Not sure if the plugin is working well yet though |
The This issue should be closed, and an issue filed on https://github.com/vslinko/babel-plugin-react-require instead. |
We have a file that imports svg without using react, so we didn't import react event if we don't use babel-plugin-react-require. Maybe a better course of action would be to check if multiple svg are imported and only add the import once? |
Ran into the same issue a few minutes ago, resolved by downgrading to 5.1.
Was the kind of error I was receiving on all files that imported an SVG file. This issue happened once I migrated to webpack 4. |
@MrOpperman |
The order doesn't matter, preset plugin visitors are always chained after user-supplied plugin visitors, at least until plugin ordering gets revamped (starting with babel/babel#5735).
It shouldn't. As mentioned by @christophehurpeau, this plugin adds a React import per each SVG, without any involvement from import MySvg1 from './close.svg';
import MySvg2 from './close.svg';
export function MyFunctionIcon() {
return MySvg1;
} It results in the following output: import React from 'react';
import React from 'react';
// ... This could be fixed by having a |
Thanks for clarifying - it’s absolutely a bug that it’s adding more than one react import when there’s more than one svg, and I’ll try to fix that ASAP before closing this. Babel’s correct to not be opinionated; but this transform is for react, and assumes you’re not using it as a global since it’s 2018. Separately, babel/babel#2135 (comment) the (unresolved) reason why this is important. Once the bug you’ve mentioned is fixed, the only remaining issue will be in the react-require transform, as detailed here. |
The logic in I have opened a PR in The above will fix this particular bug, but not the situation where some plugin Foo does the same thing as
|
@jeremejevs thank you for clarifying that it's a babel bug! I think that the first steps are to 1) fix the "multiple SVG causes multiple imports" bug; and 2) use For the potential solutions you suggested: I agree that option 2 is a bit dirty, and option 1 won't work for airbnb, where for non-SVGs, we don't want React added silently. Option 3 adds an extra dependency for us that also won't work, for the same reason - because for non-SVGs, we demand explicit React imports and don't want to use a transform to add them. |
@jeremejevs so I'm trying to replicate the duplicate issue you're talking about, and it doesn't seem to be a problem. See #39. |
@ljharb It only happens when there's no pre-existing React import, which is why it has been surfacing only for those using |
Got it, thanks. #39 now fixes that problem. |
Nice! About the options - I guess the only one left then is to borrow the code from my PR and replace |
@ljharb I just published the PR to babel-plugin-react-require: This issue can be closed now, as it'll be out on Next.js soon. 🙌 |
Issue still there... |
@jerlam06 please file an issue on babel-plugin-react-require |
Facing the same issue
Using babelrc config
kindly help me |
It still doesn't work with this config:
However it seems the |
@timneutkens this issue seems to be resurfacing with see comments here: vercel/next.js#6281 not sure how to go about solving this apart from manually adding an |
I'm hitting this issue with next@8.1.0 as well. |
Yeah, I'm experiencing this issue as well on Next 9.03 |
Can we reopen this issue? |
@adamsoffer it remains a bug with babel-plugin-react-require; this plugin already prevents a duplicate declaration. |
@ljharb gotcha thanks |
@ljharb apparently it was resolved in |
If you're still having the problem, then I guess not :-) |
I'm using this plugin with next.js, which uses
babel-plugin-react-require
. It seems that the changes in 3bab74c are conflicting with that.So now I get this:
The text was updated successfully, but these errors were encountered: