-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[BUG] Npm installs devDependencies of url based dependency (git://) #2784
Comments
Try with npm v7.6.0? |
This comment was marked as outdated.
This comment was marked as outdated.
Same problem in v7.6.3 |
#492 (dependencies starting with |
this is somewhat intentional, but there is a bug here i think. to go into further detail, when you install a git dependency (or a directory) into your project, we assume that the target is not necessarily a fully realized package. we clone the repository, we install the dev dependencies and we run relevant lifecycle scripts (like prepare) to ensure we have as close to what the published result of that package would be as possible. we then pack that directory into a tarball and install that resulting tarball into your project. it seems where we're going wrong is that we're failing to remove those transitive dependencies when we pack the resulting tarball. we'll look into this further, thanks for the report! |
Does it make sense to do this when there is no such scripts in |
Is there probably a way to tell npm that a package is "fully realized"? |
It would be helpful to have a way to toggle this behavior. My company uses private repos to host forks of various projects. Some of those projects have native dependencies that will not build correctly on npm 7, hence this behavior is actually a blocker to our adoption of npm 7. |
I don't know about Related: #3937 |
#2610 related I guess. |
hi @Greg-Smulko thank you so much for taking the time to report this issue and the great description! I'm trying to reproduce the problem described here and it jumped to my attention that what you stated as "Expected behavior":
is not in fact how it works, as much more thoroughly explained by @nlf in his comment:
continuing from @nlf's findings, I created a couple of minimalist test scenarios to validate that the behavior is indeed working as expected: Scenario 1: git-based dependency has a package with a failing postinstall scriptInstalling a dependency
Scenario 2: Removing scripts from my git-based dependencyIf I take away my
How can users being affected by this behavior proceed?Given that
ConclusionI'm going to close this issue now as I could not surface any hidden/extra bug in the expected behavior of git-based dependencies and their scripts. An ideal follow up here would be for some of the interested users to create an RFC for opting-out of running scripts for git-based deps so that we can discuss that alternative further. |
OMG I just spent three days trying to figure this out. My shop is strict. They will not give me a private npm registry which would have made this far less of a headache. Instead they just install the couple internal library packages we have as git dependencies. The docs for One of our libraries uses node-canvas and getting that to build in all relevant spaces is just a nightmare sometimes, especially on ARM architecture with our M1 macbook pros we've been assigned. But oh well, at least we can wrestle with that in the library repo itself and then just build the Google search after google search after stack question after stack question and three days later I find this thread.
Renamed the PS - Here's some google keyword fodder for the poor lost souls still on the barge of the damned like I was 😂
|
Honestly, just updating the documentation to include these other script steps as triggers for dev dependency installs would have saved me hours and hours of troubleshooting. I'm sure there are others out there floundering, wondering what they're doing wrong. A way to opt out would be great, but just knowing that the CLI looks for more scripts than just |
In our case I had to eliminate the forked dependency from our build (last year) to update to npm@7 and workspaces. If this hadn't been feasible I would probably have migrated to a different package manager. Make of that what you will. One thought regarding this:
Node now has (for better or for worse) a mechanism that allows me to override dependency resolution on a per dependency basis, so I don't think it's unreasonable to provide some sort of escape hatch in the context of installation for people stuck with this. Even if I had to literally wrap the git dep in another package that uniformly specified a rule for ALL of its dependencies I would still take it. |
otherwise, if you are against this, the least we can do is to add it to the documentation. |
Linking npm/npm#21153.
Current Behavior:
devDependency of a dependency is installed when its referenced using URL (e.g.
"git://github.com/company/myDependency.git#v10.17.30",
Expected Behavior:
devDependency should never be installed, regardless of the method of how the package is referenced.
Steps To Reproduce:
Create a dependency with this config:
Use this dependency in a project:
Run
npm install
on the project.There is a failing attempt of installing
node-sass
ver. 4.13.1, even though it should not be.Environment:
The text was updated successfully, but these errors were encountered: