-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
verifyPackageTree() errors when wrong version dependency is installed in any parent directory #4167
Comments
Just some additional context, I ran into this issue while testing and experimenting with the monorepo/yarn workspaces support in the |
/cc @gaearon was this intentional? I can't recall. |
I just faced this when trying out react-script@2 for the first time. My project structure:
Created an All tests pass just fine when running |
I am also running into this in a We have one version of This definitely seems like CRA trying to be too strict in its enforcement. Instead of checking every folder in the node module resolution path, wouldn't it be enough to check |
This is the intentional behavior. We're going to make an E2E test case to showcase why. |
@Timer Okay, thanks for the quick response. Interested to see why but I will wait for the E2E test case. Feel free to close this issue or use is as a "reminder" for the E2E test case. |
Hello, I think I'm encountering the same issue on a CRA based app, but is slightly different from what described above. Here are some details about it. Error message:
This is the
Apparently is checking for the highest up in the tree, which would make sense, but the
|
I have this issue as well. If it's intended behavior, is there a workaround other than putting the parent project in a sibling directory instead? |
@Experiment8 I am facing the same error when I am building the react apps. I tested that with the basic template. But, still getting this same error as you. Did you happen to rectify this error in your application? |
Yes same error here. Quick steps to reproduce: mkdir ~/tmp
cd ~/tmp
npm i -D [email protected]
npx create-react-app foo
cd foo
npm t |
@nicojs as mentioned above, this is the desired behavior -- not a bug. |
@Timer Any news on the E2E test case to showcase why you mentioned? |
My tiny brain has problems to understand why it would be a problem, but if it is desired behavior an e2e case would help to explain why. The 4 steps to resolve the issue don't help for this issue as well. A mention of this issue with the reason why would be greatly appreciated. |
The problem would generally showcase in a monorepo when combined with hoisting: Say you have a package The package manager hoists Now, when
This same problem exists when a user self-installs |
So it isn't a problem when the parent directory is not part of a monorepo or when you decide to not hoist the dependencies? If so, we could maybe build in this check? Right now, it's pretty much all or nothing. Side note: this hoisting business seems like a bad idea to me if it can break the dependency system. |
@Timer thanks for the example, but I still believe something isn't quite right with how the hoisting is working. E.g. in my case, the only dependency requiring babel is actually CRA (tried to remove the eslint package to check) but still the build check fails for what I shown before, preventing the production build. Disabling the check and let the build go produces a perfectly working build tho, so no problem with deps resolving. |
Maybe instead of just failling it could check which packages may have problems with hoisting. In your example, foo So it would output a message saying something like “you need to add foo to your no hoist configuration” to avoid that dependency problem That’s the case for a project I was working. We had to disable hoisting for two packages to avoid this problem, but still need to skip preflight in order to run the app |
I agree we can make this smarter -- maybe we can try to detect when in a workspace/monorepo and bail out once we hit the root of the workspace. |
I've got a similar use case to @brunolemos. It seems like a common project structure that we intend on supporting. (The proxy feature in CRA, for example, supports this project structure). I'm similarly using |
@Timer I don't fully understand the concern with hoisting based on your example here, assuming I am not misunderstanding how yarn's hoisting works. I recreated the example in a new branch. You were right that since Based on this hoisting behavior, Let me know if I'm misunderstanding the problem we are trying to avoid/protect end users from. Edit: tl;dr; Are we sure we cannot (1) Trust |
Regarding @Timer's example, which package would |
@newoga, your example misses one crucial detail - the What will happen if you install a According to this blog post - https://yarnpkg.com/blog/2018/04/18/dependencies-done-right/ - But what will happen if you install a package that requires According to the blog post above, it will target This is what @Timer tried to explain. In my opinion, That's because it could prevent a build when everything is fine. It sounds like the hoisting mechanism in yarn workspaces should make sure that dependencies that require peer dependencies are placed as close as to the required version of peer dependencies. Edit According to this issue - #1795 - the reality is not that simple. It looks like some common dependencies aren't complying with the node module resolution strategy, what is very common in the front end world, or npm makes strange decisions when it comes to placing dependencies. I have noticed that verifyPackageTree.js - https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/scripts/utils/verifyPackageTree.js#L24 - checks only specific dependencies. For monorepo users, as a temporary solution, I'd suggest setting a nohoist rule for packages mentioned in the link above. Edit 2 The "nohoist": [
"**/babel-eslint",
"**/babel-jest",
"**/babel-loader",
"**/eslint",
"**/jest",
"**/webpack",
"**/webpack-dev-server",
"**/babel-eslint/**",
"**/babel-jest/**",
"**/babel-loader/**",
"**/eslint/**",
"**/jest/**",
"**/webpack/**",
"**/webpack-dev-server/**"
] Edit 3 The nohoist above caused eslint to stop working completely in some workspaces in my project. Consider it a non-ideal solution. |
I'm having the same issue, tho using npm and jest Tree structure like bellow:
So, it seems that react-scripts, for some reason, looks for a jest version in a parent folder, rather than on it's on node_modules sub-folder For me that makes no sense, why does it have to check for versions higher up the tree? I mean, Is there any reason to check a parent node_modules directory for an package version even when the package was found on its own node_modules folder? Also: the problem is solved if the server version of jest is 24.8.0, the same react-scripts is using |
In this example:
Why would it be that If there's a reason for that that I'm missing, perhaps a more real-world example would be helpful? Otherwise, I fail to understand the argument for "why" the current behavior is intentional. (This example seems like something that might be worth reporting about, but it would instead be a case of reporting that And thus, and based on the situations in which I've seen this come up (which are very similar to what's described by nicojs), this currently strikes me as simply being a bug that higher-in-the-tree |
Also running in to this issue in a monorepo using yarn workspaces. Minimal example is here: https://github.com/ChrisSargent/react-scripts-verify-test You can see that even using the nohoist option for react-scripts (meaning all it's dependencies remain 'local' to the package), it still encounters this issue. FYI, using the nohoist options from this comment #4167 (comment) did not prevent the warnings for me in this minimal repo. This is the resulting node_modules folder in the package which should lead to correct behaviour. To me it would make most sense if the verification would follow 'normal' node module resolution rules. Edit 1: Edit 2:
|
Ok, |
Is this a bug report?
Yes
Did you try recovering your dependencies?
No. This issue presents an argument that there may be a bug in the verifyPackageTree.js logic added in the
next
branch.Which terms did you search for in User Guide?
version
,dependenc
. This does not appear to be documented (and since it is internal, maybe it shouldn't be). There is discussion regarding documenting some of the packages related to this in issue in issue #4137 (suggested by @Timer here).Environment
Running on macOS
10.13.2
.Steps to Reproduce
I created a reproduction project here: https://github.com/newoga/create-react-app-issue-4167
The project is a simple node package that depends on a version of
jest
that is incompatible with[email protected]
. The project also contains a directory (cra-app
) that was generated bycreate-react-app
. Thereact-scripts
dependency in that sub-project has been updated to2.0.0-next.47d2d941
.git clone https://github.com/newoga/create-react-app-issue-4167
cd create-react-app-issue-4167
yarn
yarn run
Expected Behavior
From a user perspective, the
yarn run
command should not error and the application should start. The user did not manually install an incompatible version ofjest
in thecreate-react-app
generated project. The version ofjest
in the generated project'snode_modules
is the correct version and parent directories should not have an impact.From a technical perspective, the
verifyPackageTree.js
logic should see that thecra-app
project contains the correctly installed version ofjest
and stop checking parent directories. Parent directories should only be traversed ifjest
is not installed.Actual Behavior
An error occurs because parent directory depends on a version of
jest
that is incompatible with the version ofjest
thatcreate-react-app
generated project depends on.Reproducible Demo
https://github.com/newoga/create-react-app-issue-4167
Edit: Updated the issue number on the links.
The text was updated successfully, but these errors were encountered: