NPM Workspace dependency resolution differing in production builds #86641
-
BodyI think this is an npm workspace question, but for full context this is within an Nx monorepo: I have a few apps which use varying dependency versions (I know, I know...not ideal, we're working on it). When running appA locally everything "just works". When it gets built for production, it crashes due to an older version of a dependency being used (and, thus, the code being incorrect). The "older version" of the dep is found in the root node_modules, and the "newer" (correct) version is found in appA's node_modules. Why is the root-level dependency being used in prod builds, but the app-level dependency being used locally? This application is being built with craco. Using node@18, npm@9.6.7, nx@16.9 Guidelines
|
Beta Was this translation helpful? Give feedback.
The dependencies specified in the root package.json take precedence over the app-level dependencies. This behavior ensures consistency across the entire monorepo and avoids duplication of dependencies.
In your case, it seems that the older version of the dependency is specified in the root package.json, causing it to be used in production builds. To resolve this issue, you can try the following steps:
-Update the dependency version in the root package.json to the desired newer version that works correctly for your appA.
-Fine-tune Dependency Versions: If you have different packages in your monorepo depending on different versions of the same dependency, you can explore techniques to fine-…