-
Notifications
You must be signed in to change notification settings - Fork 2.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
package.json per app #1777
Comments
A related question/problem we are facing with using a node graphql-api is:
To solve this, we are using a separate (specific) However, this results in other problems like:
So the question really is:
N.B.
|
Thanks for submitting the issue. You could create a package.json per project, and for instance use something like We believe in the single-version policy, where, for instance, all applications using NestJS, use the same version of NestJS. Even though it looks a bit crazy at first, we think it is beneficial. Companies like Google do it. So having one node_modules at the root is very similar to what Google does (with a single I'll try to find sometime this week to author a guide on single-version policy, where I'll also cover how to add multiple package.json files if you decide that single-version policy doesn't work for you. |
Nice thanks @vsavkin ! In the meanwhile while you create the documentation, do you have an example of a project with different |
Thanks @vsavkin We love the ONE The only reason why we have a separate Would be great if that could be part of the guide. (each app lives in it's own docker container) |
Single version policy: Fantastic, great path for most projects. Single list of packages: This is a little harder to deal with as @the-ult suggested. I would love to see something per-app/library that limits which packages (name only, not repeating or varying the version!) the app/library can depend on. This data could also fuel a mechanism to generate a minimal production-only package.json algorithmically when needed. (I wonder if this might be possible today by omitting package.json from implicitDependencies in nx.dev...) |
I totally agree with the previous suggestion of generating a minimalistic package.json for production. However, we would also need a package-lock.json to prevent the runtime production app from fetching different versions than the nx workspace. We mainly need this to get a production app that is as small as possible since it is deployed as a Google Cloud Function |
I'm starting to see the point about one package.json. I've had to deal with multiple lodash versions in the past and it's a pain. Having said that, just like the previous comments, I need a small |
I'm following this discussion and I understand that single-version policy may be an issue for some. But for minimal node server deployments (i.e. not deploying the entire node_modules) why not simply bundle the node app? |
Quick update: We are working on a course that will cover things like single-version policy. Stay tuned. |
I think having one package.json per application is useful if you want to publish your libraries or applications separately in the future. Is there anyone who has solved that problem? |
I think it is mainly because there still tons of issues with bundle apps using nx with webpack, nestjs, typeorm, and docker. Each of them is great. But using those significant parts together is terrible. |
Reading through this because I have a use-case with several "sub-applications" that are lazily loaded into a single core Angular application, and they need to be developed by independent teams. I haven't seen that particular wrench thrown in this thread yet. While the single package.json strategy works great for a single team, I am struggling with how these large companies handle the seemingly incredible cooperation costs of having multiple teams operate with a single package.json. I am looking for an architecture where we have a core Angular application that is comprised of several sub-applications (which is now facilitated by Nx, and previously by the vanilla Angular CLI.) I wanted each sub-application to have a private package.json to define dependencies specific to that project, while keeping globally shared dependencies (such as Angular itself) in the root-level package.json. This dramatically cuts the cooperation costs between teams; if Project A needs Of course, we still have the issues of "Okay, everyone upgrade to Angular N+1 on mm/dd/yyyy!", but I think having private package.jsons can remove a vast majority of related versioning issues. This all works fine for JIT compilation. Issues arise when you try and build it with AoT. Is there a recommendation on how to handle this type of situation, with multiple teams working on individual sub-projects under the same global project? |
I like the idea of having a single master |
I use generate-package-json-webpack-plugin to solve this problem. |
@kraiz Thank you for the tip. Do you know if this plugin can be used for Angular apps as well to weed out the backend (NestJs) dependencies? In other words, is it smart enough to parse Angular source code and build a list npm packages that app needs? |
You don't need it for angular because it's webpack configuration is already making sure you only get the stuff you need into your bundle files without the need for an external runtime dependency folder (node_modules). |
@kraiz Got it. That makes sense. |
Ahh, didn't know that the lockfile can be a superset. Thx, will try that! |
How does Google manage to update all (i can imagine they have hundred/thousands) apps at once? From my experience, you always get:
I'm pretty sure I didn't cover all the scenarios but they all lead to late migration / no migration at all. Even though I agree it's important to encourage every app/team to stay up to date with the latest releases and use the same version, it becomes more and more complex over time until it's not even possible anymore. One strategy here for
That being said, it's probably a lot of work to maintain both possibilities and much more work for many features. On the other hand, keeping the Whatever you decide, keep up the good work 👍 |
@MaximeBernard Are you using Angular with multiple package.jsons? If so, how do you manage to get AoT compilation to work with multiple package.jsons? |
@meeroslav At this point, it'll be faster for us to harmonize the Angular versions 😞 It sucks that the documentation says Yarn workspaces (1) /Lerna-style monorepos (2) are fully supported whereas in reality, using any type of workspaces (with separate package.jsons) with Nx creates issues like this one. Would the alternative be to give Nx its own little box as a separate monorepo package, separate from the actual projects it compiles/manages? |
@boxmein what do you mean by:
? I have just set up NPM workspaces (not yarn or lerna or pnpm workspaces) in our NX monorepo, and so far, no big issues. The only 2 things that didn't work for us were:
|
There is one major pitfall to using a proper Yarn workspace with Angular: the Angular Compiler
So what we were trying to do was the following:
Now there are two ways to run Angular Compiler on
This meant we did not have a way to run the Angular compiler on As well as that, |
At this time, we chose to stop leveraging Yarn workspaces to properly manage per-library dependencies, merged all package.jsons together into a mega-package.json, downgraded our Angular 12 code to Angular 11, and used "path aliases" to create individual "libraries" like the official Nx doc instructs you to. |
@ianldgs That's why I said above that Yarn workspace support in Nx is not really there.. because in the Angular case, you run into issues when using yarn workspaces instead of the "true Nx way" of having a single mega-package.json. You're essentially limited because the Nx builders have to be in the root project, and there's no real way to make it utilize the version of |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Can someone link the official NX response and suggested route to do this? I need NX to npm install using different node versions per package. I'm not finding any clear answer and hoping from what the official answer or suggestion was here will be highly beneficial. |
@boxmein, your use case is too specific, so Nx will never support it in the integrated approach with the
Using different packages per project in monorepo is supported, but how would using different node versions work? |
@meeroslav I see several "lock file pruning" mentions in the release notes, has this issue been resolved? If not do you have any ETA to share and is this issue the best place to monitor to be informed of the progress? Thanks for Nx, it's such a great tool! |
Thanks a lot @meeroslav I've found the doc for that feature. Using yarn is an option for my docker images (it only requires installing one more dependency). It is however not an option for deploying to Google App Engine which only supports npm. It looks like the support is good enough for my need as is and knowing that it will get better is great. Edit: yarn is actually supported on GAE 👍 |
@meeroslav I understand where you're coming from - however it's not a matter of specific use-case... it's more about the fact that the core feature of a Yarn workspace is that NPM package versions between two projects are not related to each other. They are well-defined and specified in I had a bug in my repo that happened because Nx requires all builders (e.g. In my case, with this workspace structure:
The package It doesn't matter which node version it is, just the fact that builders have to be defined in the root project, will cause issues in any Yarn workspace. A little extra: the root cause will actually be hidden from you, because Yarn will randomly choose one |
@boxmein I see what you mean. The problem, in your case, is different from that we require the builders to be in the root (Yarn, anyways, installs all the workspace dependencies recursively in the root). The issue is that we run the builder from the root pointing to your project, which results in always using the same version regardless of what your package requires. This is an interesting problem we need to take a better look into. Can you please open another issue explaining this? |
Yes, that's what we were struggling with and it led to us essentially creating a mega-package.json that contains 3 microfrontends' dependencies. We would still eventually like to decouple them so that they can have smaller, more focused package.json files. This may also cause differing versions of
You're correct in that, unless a workspace requires a different version. Then the
Sure thing |
Closing this issue as it has been resolved the lock file parsing, package json generation and lock file pruning. |
@meeroslav could you add a link to the documentation of that? 🙏 |
@LuisCusihuaman the documentation is slightly outdated but most of the information should be there: |
is it work for FE apps as well? |
It's especially for apps. Published libs don't need lock files and they usually have |
@meeroslav would you recommend having an explicit package.json on libs? |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
First of all,. just like to say thank you! I love nrwl nx and how well organized the code looks like when using nx! Also, it's awesome you folks are investing in React!
Prerequisites
Please answer the following questions for yourself before submitting an issue.
YOU MAY DELETE THE PREREQUISITES SECTION.
Expected Behavior
Is there a way we could have a
package.json
per app? If you are using docker, and would like, let's say, have an angular app running in one container, and the nest api into another container, then both containers will have to runnpm install
over the all the npm packages even when angular packages are only a subset of all the packages (and viceversa with nest). Additionally, if we donpm install
inside the containers, huge packages like cypress will be downloaded, even if they have nothing to do with the api (nest) build. This take its toll especially when running a CI build in travis, circleci, etc (yeah, I know there is cache, but it's not 100% reliable).Please describe the behavior you are expecting:
Would love to see every app having different package.json. Plus I think it is cleaner. Why having one
package,json
to rule them all? Seems very tightly coupled.Current Behavior
What is the current behavior?
There is only one package.json for all apps using nx
Failure Information (for bugs)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Context
Please provide any relevant information about your setup:
The text was updated successfully, but these errors were encountered: