-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Add a warning about using different builds #6361
Comments
Also, thank you to @pshrmn who took the time to explain this issue to me in #6209 (comment) |
We had originally added the transform-imports function in #5095. The motivation was bundle sizes from duplicate modules, but this has an overlapping concern that's now exposed as a header. Regardless of the approach taken, we'll want to make sure we keep the bundle size in mind. Fixing one will likely fix the other. It'll be annoying, but I'd suggest setting up a test repo, Rollup has got good DCE built-in nowadays and Webpack respects the sideEffects: false key we added to the package.json's. So, I think it should be easy enough to solve by just following best practices. |
Is this also a concern for libraries that More specifically if I have a library of more complex components that contain various |
@jimthedev as long as every Issues are most likely to be cause by:
import { Route } from "react-router-dom"; // esm
import Link from "react-router-dom/Link"; //cjs
|
Now that we have a single entry point for each build, this could probably be as easy as defining a global variable like if (globals.ReactRouterModuleFormat && globals.ReactRouterModuleFormat !== "cjs") {
// warn
} And we would only do this in |
Hi, I have a package A (built with CRA) that uses another package B built using babel in a monorepo configuration. The code looks like this // Package A
import { BrowserRouter as Router } from 'react-router-dom';
import B from '@monorepo/B';
export default () => (
<Router>
<B />
</Router>
); // Package B
import { Link } from 'react-router-dom';
export default () => (
<div>
<Link />
</div>
); They both have the dependency react-router-dom: ^5.0.0 But i get the following error : |
@hugomallet can you verify that they are using the same build? It is possible that one is importing the CJS build while the other is importing the ESM build. I think that the most likely scenario for that would be if one of the packages doesn't use the |
Hey @hugomallet we had literally this exact same problem here since a couple of hours. Managed to fix it by enforcing the ESM build by importing every |
@pshrmn How can i check that they use the same build ? I have downgraded to 4.3.1 for now. |
I would find the package in your |
@hugomallet @pshrmn we are having this exact same problem using a lerna monorepo with yarn workspaces. Except in our case we are importing A into B taking from hugomallets example. Have triple checked all versions are the same and even attempted enforcing an import from react-router-dom/esm/react-router-dom but we still go the same invariant error. Downgrading to 4.3.1 works as well for us for now |
I think the workaround with lerna is to hoist dependencies. Webpack seems to bundle dependencies based on relatives paths (not packages versions). So if two files require react from two different locations then react will be duplicated in the bundle (which is not permitted with react-router@5). |
Before 4.4, you could do this w/out problems:
It's not very obvious, but those two
import
statements may actually reference different builds. The first one is using our CommonJS build, and the second one may be using the ES modules or the CommonJS build, depending on how your build is setup and where you told it to find files from thereact-router-dom
package. If you're using webpack (which you probably are) then it's probably pulling from the ES modules build.In the case where
<Link>
is coming from a different build (or any other component, e.g.<Route>
), you will currently run into an error like this:This is because of the context object mismatch, which is a problem introduced by our using the new context API. Basically, each build has its own context object, and components from different builds can't be used together.
For this reason, I think it'd be nice to provide a better warning for folks who might be pulling the files from different builds accidentally, like I was doing (see 6460fe0). Maybe something like:
The text was updated successfully, but these errors were encountered: