-
Notifications
You must be signed in to change notification settings - Fork 240
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
[RRFC] Add nohoist option for workspaces #287
Comments
What I'd prefer, rather than adding "nohoist" and having to manually configure it, is finding a way for nothing to hoist, so that each folder's |
sounds very much likes "pnpm" approach of doing things. |
Current status:
|
I'd amend this to say, "hoisting" is the improper term in every case - that what is actually desired is control around "sharing". I think by default, the root, and individual subpackages, should share all peer deps, and all subpackages themselves, but observably share nothing else (iow, it's fine if they actually share the same copy of lodash, but a workspace shouldn't be able to require lodash unless its own dep graph includes it). |
Hi guys is there any progress on this issue? I really want to use npm for workspaces but I can't because react-native projects require a nohoist option.. |
This would actually be very helpful for monorepos with Angular and certain dependencies that look for angular core and common as peer deps. I'm encountering a scenario where I have an angular theme library that looks for angular/core and angular/common as a peer dep but it's getting hoisted to <project_root>/node_modules. Angular isn't because I have other packages that depend on a newer version of |
I would also like to add my support for a nohoist option. I've ran into problems with eslint configurations in a monorepo because it expects to be installed at the local package level. |
I agree. A |
I'd like to add an additional use case for being able to disable hoisting in workspaces. I recently had to abandon workspaces in favour of Lerna to resolve this for myself. I am working on a very large project which has quite a few serevrless components to it. We have a bunch of queueing and lambada workers. The project is setup with the following folder structure
each of those folders is a npm package which maintains its own set of dependencies. Some shared some not, some packages that only exist in this project and wont be published to any registry. Part of publishing an aws lambda is the package needs to contain all of the dependencies in a package (ignoring layers for now). What we want to be able to do is, after an install be able to zip up each of the lambdas with all and only their dependencies so the cdk deployment can pick that up and push it out too aws. With hoisting everything is in the root which is many millions of unneeded files for each of the lambdas. Not only that, you must handle the folder structure of walking up the tree and pulling everything down to the lambda folder or you end up with a deeply nested folder structure in the lambda. I was very close to creating some sort of symlink system of constructing the |
Our use case is very similar to what @will-fagerstrom just described, with a twist of Lambda Layers. We pack all 3rd party deps to the shared layer (as described here) and
I would rather go back to NPM than to Yarn 2+. |
If and when something like this lands, #375 is probably going to be the first step. If you have a moment, please go weigh in there about how this will affect your use case, if it will satisfy your needs, etc. I will update that PR now with my notes from our discussion in the open RFC call a few days ago. |
@isaacs - Thank you for pointing out the proposal in #375. As you've mentioned in the proposal,
This is exactly the way we use |
@khitrenovich So, iiuc, you're relying on all dependencies being local to the workspace's I think #375 will still satisfy that need, no? Basically, "nohoist" will be the default, unless you have a peer dependency, or a dependency on a sibling workspace. If we implement it by symlinking sibling workspaces into one another when they have a dependency on each other, and they are listed as |
Not exactly. We are developing a serverless system, with backend implemented mostly with AWS Lambdas. Each packaged lambda is supposed to be self-contained (that is, contains both its own code and the dependencies). Yet, it is possible to compose a single lambda from several so-called "layers" and it is possible to share those layers between several lambdas. (more) Here is a sample of our current workspaces configuration:
Our lambdas ( Besides the lambda-based backend services the project contains API definitions, client-side workspaces etc. - all those are not affected by Maybe I'm misinterpreting what #375 is about, but I don't see how it will be possible to configure the same dependency of the same version to be hoisted in one workspace and not hoisted in another workspace. |
Well, no, effectively nothing would be hoisted at all, except explicitly declared root dependencies. Any non-peer/non-sibling dependencies of the workspace itself would not be hoisted beyond the workspace boundary. For sibling workspace dependencies, we could create a symlink in the dependent workspace's |
Same problem here, i'll just move to yarn again |
I am having this problem for Next.js |
@souzaramon might want to give PNPM a try, as far as I understand it never hoists anything because it utilizes links so there is no duplication... |
I'd like to +1 the I maintain a monorepo that has an electron app and web app that serves the same frontend and shares backend logic but when I try to distribute the electron app, I get an error because electron is hoisted. Relevant discussion: electron-userland/electron-builder#3984 (comment) |
Same here -- need this for deploying Google Cloud Functions which always use npm for the cloud build even though I use yarn locally. I currently can't deploy cloud functions with Node 16 because npm rejects the workspaces.nohoist section in my package.json. |
Thank you @mrkpatchaa 🙌🏼 |
This issue is going to single-handedly force me to use Yarn in the RxJS repository when I really don't want to. :\ My issue is that I have a documentation app workspace that is using Moving to Yarn fixed this cleanly, but I'm a bit sad because all of my muscle memory is npm. And, like most tooling, if I move over to yarn for this project, it's unlikely I'll move back until I have a reason to... because messing with tooling that works is silly and time-consuming. |
+1 for this feature request |
+1 |
Today I tried npm workspaces for the first time, then ran into this, and had to abandon the idea. Without nohoist or similar configurability, npm workspaces cannot be used with projects whose packages use I had to go with Yarn for managing install and linking. First time using Yarn, and I was greatly impressed.
What we really need is workspaces hosting/sharing/whatchamacallit options that enable a git submodule to work on its own exactly the same way as when inside of a super module. Basically what @ljharb said, that the I would be ok if node_modules in the sub-packages contain links to the modules in the root, as most static web servers operate fine that way (or have an option to operate that way) even if the link goes outside of the web server's root folder. This would be ok because then the If links to the root would become a feature, the links should be in a structure that mimicks the same structure that would be in place with a regular |
This is a must-have for us. We're trying to migrate away from Lerna since it dropped install support in v7 in favor of npm workspaces, but due to our liberal use of patch-package and copying files out of node_modules (legacy code, we're trying to move away from it but haven't been able to yet) it keeps breaking. When I If it were up to me, I would stick with Lerna, but unfortunately that ship has sailed, so I guess we're over to yarn until this is fixed. Hopefully that doesn't break too many other things. 😞 EDIT: we decided that switching to yarn was too disruptive, so instead we moved all our patches up to the root where they were actually being installed. Not pretty, but it works. |
@trusktr Just want to say thank you for your edit - we're in a similar position and actively exploring options to move away from Lerna. We had hoped to move back to npm, but without hoisting limits of any kind, it's just not an option for a codebase with a significant number of packages. |
Just dropping in to say that I have an example repository that demonstrates the issue we are having with npm workspaces and hoisting. |
This is the exact problem I'm having right now with a new monorepo I'm putting together for a new project at work. We're 3 years into this feature request with no progress. Is there any hope? I think npm has a great workspaces implementation, but this is the Achilles heel. Many projects need direct, non-hoisted dependences inside of monorepos, for deployments. You cannot use npm workspaces for this very common, modern scenario. Yarn is a mess. I'm left looking to pnpm, but I wish I didn't have to. I see a lot of "Well, I'll just use pnpm" here, but I tried that...and correct me if I'm wrong, but it still creates symlinks when you turn off hoisting. This defeats the purpose and doesn't work for Lambda and other types of projects which need to independently bundle the dependency. What's the status on this? Will it ever happen? Can npm keep up? |
If npm can't keep up, there's at least this good news: Both After you install Node.js, you can run In case anyone migrating from npm(+Lerna) chooses to go with Yarn, there's one issue that you should be aware of: in some cases Yarn will absolutely not dedupe packages that are within compatible version ranges (even if you manually run |
works for me. I had some trouble FORCING the installation of some packages to go into root because there were some peer deps that had other versions, so I installed them in root manually. then I deleted them from root package.json (but not package-lock.json) again and moved back to @my-org/my-lib and voila, they are still being installed in root on successive npm i |
Not fully tested, but if i specify |
你的邮件我已收到,查收后会尽快回复!:)
|
Pipeline files for a UAT and production deployment, including: - .NET Core Webapp - Nextjs Node App - .NET Functions App And new pipeline environments: `NUH RedCap Monitor UAT` + `NUH RedCap Monitor Prod`, checks needed to be added on the production environment by an admin. Also: - Updates an incorrect typescript import - Removes Cors Framework package. - Removes the npm workspaces for now, as deploying with this is not easy, see: npm/rfcs#287 Hopefully can come back to implementing it with workspaces, but this is the most direct route to urgent deployment. - Adds a `server.js` file for the app service to run the Next app as, via PM2: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs?pivots=platform-linux#run-with-pm2 Related work items: #125090, #125102
Hey folks, what's the status on this? Will it ever happen? |
你的邮件我已收到,查收后会尽快回复!:)
|
Electron Forge doesn't work with npm workspaces. See: #53 And: electron/forge#2306 And: npm/cli#7029 And: npm/rfcs#287 This gets the app working when packaged.
I have struggled with this issue for a while and eventually found a sort of workaround for a pretty specific case. This approach creates two separate Example: cd my_monorepo_root
rm -rf ./node_modules
npm ci --install-links --ignore-scripts --workspace=azure-functions
cp -R ./node_modules ./packages/azure-functions |
你的邮件我已收到,查收后会尽快回复!:)
|
Motivation ("The Why")
Yarn already supports this option. It makes it possible to work with tooling that expects certain modules to be located in inside the same package that consumes them.
Example
In order for a React Native app to build properly within a monorepo, some packages that react-native depends on must reside inside the node_modules folder within the app package. With yarn, I'm able to accomplish it with this configuration:
How
See: https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
References
The text was updated successfully, but these errors were encountered: