How I can publish a library with all dependencies #27150
Replies: 105 comments 1 reply
-
After a week try many solutions I found a way to publish a library with all dependencies.
|
Beta Was this translation helpful? Give feedback.
-
I find this to be a workaround for something that I would expect to exist out of the box. |
Beta Was this translation helpful? Give feedback.
-
@nemanjamilosavljevic-newtron Exactly, That is my workaround solution. I read all issues relate to publishing a lib in repository issues and in the Slack channel but there is no answer so I decided to read, understand Nx source code, and finished with the custom Rollup build script. I think Nx have done their job. Because we are building publishable libs and used it locally. The import statement can be treated as an external package. Although it still has some issues with this approach I think it relates to different issues like export package.json dependencies. Do you have any suggestion? Should we re-open this issue? |
Beta Was this translation helpful? Give feedback.
-
I also think that the framework is super nice! From the slack channel I've learned that all libraries in question should be publishable, however, I've tried that approach, and it hasn't worked. |
Beta Was this translation helpful? Give feedback.
-
Ya. Because I just want to publish only one package instead of many packages and take time to manage and deploy them so I decide to use custom Rollup Script. What is your current problem with publishable libs? Btw. I will reopen this issue. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Comment to keep this issue open |
Beta Was this translation helpful? Give feedback.
-
@dangviettuan @nemonemi Commenting to keep this open. definitely doesn't feel like a feature we need to hack together to work as expected. |
Beta Was this translation helpful? Give feedback.
-
Hi @vsavkin |
Beta Was this translation helpful? Give feedback.
-
I struggled a lot with this over the last few days trying many many things, I have some core helpers and types which I wanted to include in a publishable UMD app. In the end, for me, it was very simple to bypass the Maybe this helps some of you, I added the helper and the types like normal.
Then I have added the exact locations of where these things can be found to the
|
Beta Was this translation helpful? Give feedback.
-
Hmm, I feel like this is a recurring issue. There was a long thread where people asked about ability to bundle multiple workspace libs (not event buildable ones) into one package. It was closed with a decision that NX does not support it, and you shouldn't do it. That being said I very much disagree with that decision, and existence of this new issue suggests that I am not alone in that. I do agree that for 80% of cases making every lib publishable is the way to go. But there is that remaining 20% where that doesn't make sense. Where I work we use monorepo for my team, not entire organisation. We are expected to deliver a package that other team consumes. They only need that one package, yet we end up building 10 of them because of that restrictions. No one cares or needs remaining 9. We use them to structure our code and create boundaries but we are forced to publish them. This also makes the build and publish steps extremely longer, as I am not building and publishing 1 but 10 packages. I know that NX Cloud could make that a little faster but:
Don't get me wrong, this is a great tool. I use it in my private repository, but to introduce something like that to the work environment is a lot harder. There is pricing, but also security implications, not to be done overnight. |
Beta Was this translation helpful? Give feedback.
-
@Bielik20 Maybe you shouldn't break them into 10 libraries. You can have multiple modules in one package. I don't see much benefit to break it up unless it helps speeding up the build process because of the incremental build. But in your case, it doesn't. Maybe you shouldn't break it up. As for NX cloud, I think it makes it much faster. And I think it worth the money to pay NX. We want open source projects can have a way to live and grow. |
Beta Was this translation helpful? Give feedback.
-
@maxisam Yeah, that 10 libs and 1 was a simplification, sorry I didn't want to dive too much into details. It is a couple of libs that hold some "shared" functionalities and then couple that "really" get published. Still two libs that "really" get published are never included in the same project, so it would still be ok to bundle all the code inside. Having it split that way allows us to only run tests and publish those that changed using NX affected. My point is that, there are use cases where you would want to bundle multiple libs together. Another issue is that the way I publish those libs is suboptimal, but I don't know how to do it in NX, as there is no mechanism to track version of individual libs like lerna does. I think there is somewhere here issue for that as well. So when I detect that lib changed I need to republish all its dependencies with a new version (so no NX cache for me, because I need to bump version) even though they have not changed. Now version is not committed, but kept as a github tag (using semantic release), and I really do not want to commit that version to repo. We are getting off topic, but I am trying to illustrate here is that there are many use cases and sometimes (not most of the time, but still) bundling everything into one lib is actually a way to go. |
Beta Was this translation helpful? Give feedback.
-
@Bielik20 Well, like you said you want to avoid unnecessary test and build, so you split it. Therefore, it is unfair to say "This is a paid solution created by nrwl to solve the problem manufactured by nrw". You had a problem already and NX is just trying to fix you problem. :-) Just a thought, have you thought about using dependency in package.json in the library? Btw, why do you need to republish all its dependencies with a new version? for maintenance purpose? I think your second question is more about DevOps. |
Beta Was this translation helpful? Give feedback.
-
@maxisam I don't want to spam here, I am happy to discuss details with you though. Since there is no messaging on GitHub, if you want to talk in more details, please create an issue in here ;) Here I just want to clarify. I think NX is a great tool and I love using it. NX Cloud is also a great idea. What I tried to say was that given NX is essentially a DevOps tool, it lacks in flexibility when it comes down to building publishable libs. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
please unstale |
Beta Was this translation helpful? Give feedback.
-
This has been addressed with our new Nx release command: https://nx.dev/features/manage-releases Please check that out and let us know what you think! |
Beta Was this translation helpful? Give feedback.
-
@FrozenPandaz can you provide an example of how the release command addresses the concern here? It doesn't seem to have anything to do with bundling libraries inside of other libraries |
Beta Was this translation helpful? Give feedback.
-
The last time I was told to use the |
Beta Was this translation helpful? Give feedback.
-
Ah, sorry. I've reopened the issue. 👍 |
Beta Was this translation helpful? Give feedback.
-
Thanks to everyone who has commented. As someone who just spent ~13 hours going slowly mad thinking he had forgotten or was crazy or didn't survive his last plane trip because this scenario just wasn't working... This sure would be nice to have! It's not obvious/spelled out at all that you can't have a normal nx library that is imported by other published libraries. And attempting to do so causes the I can confirm that
where Anway +1 and thanks to all the folks who have commented here and helped. |
Beta Was this translation helpful? Give feedback.
-
First most, I am not that experienced with What I am expecting is, during the build
Here is my repo and attached screenshot of the error I am getting. |
Beta Was this translation helpful? Give feedback.
-
Also, seem like |
Beta Was this translation helpful? Give feedback.
-
There is very basic example where this is required for us and I'm surprised that no one mentioned it. However, we also have utility methods across those libraries which we want to share with other teams.
And like someone else said |
Beta Was this translation helpful? Give feedback.
-
I see it's possible that the decision makers in the nx team are confused by the name of the feature It's either misnamed or not documented enough, as a result there's evidence (I encountered this more than 2 times, including in this thread) that the nx team thinks that library publishing is sorted out despite it's not. So far, the I don't exclude that they are removing The usual conversation about the publish feature could easily be "do we have a way to publish?" - "yes we have I'd hate this to be the case. NX team, please let us publish packages. |
Beta Was this translation helpful? Give feedback.
-
This is the key issue for us as well when trying to use the "external" feature, nothing else in Nx seems to be designed around the idea that "externals" exists. Apparently it's supposed to be understood as a "build tool specific feature" (like specific to tsc, rollup etc.) and not an "Nx project graph" concept, which doesn't make any sense to me. It seems like Nx is occupying a confusing half way point between actually understanding the full scope of how your libraries depend on each other vs. just making it your problem to keep track of. We've tried using the dependency checks rule in our repo but due to the amount of "ignore" statements we have to include in it it basically isn't useful or trustworthy for us, we are pretty much back to just keeping track of dependencies manually. |
Beta Was this translation helpful? Give feedback.
-
Came here from notification. Can someone point me to blog post / info about deprecating It is a feature we are really relying on. Removing that will make our work way harder than it needs to be :/ |
Beta Was this translation helpful? Give feedback.
-
I'm only aware about this https://nx.dev/nx-api/js/executors/swc#external |
Beta Was this translation helpful? Give feedback.
-
Hi all! First of all, I'd like to apologize for the lack of feedback here. Bundling non-publishable libraries is a recurring issue in the repo, which might highlight some gaps in our docs and potentially the need for some extra diagnostics in our executors to provide guidance. We'll be taking a look at improving in that area. I'd like to make a key distinction in this matter: building and bundling are two different things. A lot of the confusion comes from trying to have compilers like Ultimately, we came to the conclusion that trying to add those features on top of tools that don't support it was not the right approach. There are other tools available to build and bundle code (e.g. This is why the So, to summarize, if you're using one of the
|
Beta Was this translation helpful? Give feedback.
-
I got an error while trying to publish my library. Here is example source code: https://github.com/dangviettuan/nx-publishable
I have:
When I build the button showcase lib an error occurs like the picture below
Originally posted by @dangviettuan in #3602 (comment)
Beta Was this translation helpful? Give feedback.
All reactions