I've come across an issue where one of my transitive dependencies went missing from the NPM registry, either due to a user error, or some other action. Being used to converting plain java projects to maven, I would depend on install plugin and install-file(1) goal to create a pom.xml file for that jar (a package.json equivalent), and it would be put into local repository under .m2 folder. Afterwards other projects could refer to it as if the package was available remotely.
In NPM I'm seeing that an equivalent to "referring to local package" works via link sub command, but what it really does is writes absolute path on local system to the needed package. That is great in scenario when you control a dependent package, but not so much when you don't.
I've also attempted to do the naive way of "installing a package globally" (such as using github tarball), because on github the release, and source code are still present. But since the tool that's also fetched from the NPM registry specifies that it must pull dependencies from the registry ignores the globally installed version of that library and fails. The command line of this would be as follows:
npm install -g https://github.com/{user}/{repo}/tarballs/{tag}
added 915 packages from 60 contributors
npm install -g "foo-cli#{tag}"
npm ERR! code ETARGET
npm ERR! notarget No matching version found for {repo}#^{tag}.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'foo-cli'
npm ERR! notarget
This does raise several questions:
Does local registry exist?
How do I tell NPM to first check "locally installed" versions for tools I do not control?
Am I stuck forking the tool to "link" it against my locally installed version of missing library?
Related
I've been struggling with a module that does not build after running npm rebuild (namely, #getinsomnia/node-libcurl), even though it does on npm install without --ignore-scripts.
I workaround that by running npx node-pre-gyp install in the module directory, but I'd like to understand why doesn't this behave as I expect it to do - build the module.
npm docs for npm rebuild say:
This command runs the npm build command on the matched folders.
What does npm build do though? Documentation for it only exists for npm v6 and not any newer releases, I can't run npm build on my npm v8 either ("unknown command"), and even that documentation doesn't say anything to me:
This is the plumbing command called by npm link and npm install.
It should generally be called during installation, but if you need to run it directly, run:
npm build
I'm in the process of trying to upgrade some npm dependencies of a project I own, and I'm getting a "conflicting peer dependency" error.
I see a lot of questions on this site asking for help fixing such errors. However, I've struggled to find information on what these errors actually mean. I feel like if I understood that, I'd have a chance of figuring out how to solve the problem on my own.
Here's the error message I'm trying to interpret:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: #angular-devkit/build-angular#0.1102.5
npm ERR! node_modules/#angular-devkit/build-angular
npm ERR! dev #angular-devkit/build-angular#"~0.1102.9" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev #angular-devkit/build-angular#"~0.1102.9" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: #angular/localize#11.2.10
npm ERR! node_modules/#angular/localize
npm ERR! peerOptional #angular/localize#"^11.0.0 || ^11.2.0-next" from #angular-devkit/build-angular#0.1102.9
npm ERR! node_modules/#angular-devkit/build-angular
npm ERR! dev #angular-devkit/build-angular#"~0.1102.9" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
This can be reproduced by running npm install in the root of this Github branch (I'm using npm 7.10.0.)
My general understanding of a "conflicting peer dependency" error is that some package I depend upon is expressing a peer dependency on a package version spec which does not match the version of that package that I actually have installed.
For example, if my project has direct dependencies on packages A and B, and I have version 12.0.0 of A installed but my version of B has a peer dependency on ^11.0.0 of package A, then I will get a conflicting peer dependency error, because I'm using B with a version of A that it is potentially incompatible with.
Therefore, my best guess as to what this error message could mean is that some package I depend upon has a peer dependency on #angular/localize version spec ^11.0.0 || ^11.2.0-next, but this spec does not match the version of #angular/localize I have installed.
When I look at my package-lock.json, I do see that the node_modules/#angular-devkit/build-angular entry has an entry "#angular/localize": "^11.0.0 || ^11.2.0-next" in its peerDependencies.
However, this is the only mention of #angular/localize anywhere in this file -- or indeed in package.json. I haven't explicitly requested for it to be installed. Furthermore, it is marked as "optional": true in the peerDependenciesMeta of node_modules/#angular-devkit/build-angular. So it's surprising to see an error message related to it.
The error mentions that the specific conflicting peer dependency is #angular/localize#11.2.10. I don't see where that version number is coming from. But regardless, it actually seems to match the dependency specification underneath: if I go to semver.npmjs.com and type in #angular/localize as the package and ^11.0.0 || ^11.2.0-next as the version range, I see version 11.2.10 of the package highlighted in green, indicating that it matches the range.
So I'd really appreciate some help understanding in detail what this error message is telling me. I don't know why npm is trying to install 11.2.10 of #angular/localize, or why it thinks this conflicts with the peer dependency specification of #angular-devkit/build-angular. It feels like I might be misunderstanding this message completely.
I'm guessing this boils down to some kind of incompatibility between the latest published versions of some of the Angular packages. If anyone has any pointers on how this particular error should be fixed, that would be great -- but I'm much more interested in simply understanding what the error message is telling me, so I can work it out for myself.
Recommendation:
Check out Yarn.
I was able to circumvent the issue in NPM by using Yarn instead of NPM. Yarn is basically a wrapper utility around NPM that adds extra features, which are super useful. It's especially helpful for managing NPM dependencies better.
For instance, it can check if a package is already installed on your machine for another project, directly or as a sub dependency, and can reuse that installed version rather than re-installing a copy of the same package; saves space and makes for faster installations, especially with some of the most common dependencies.
So, due to the optimized way Yarn handles dependencies, I think it helps avoid this issue faced by the OP.
Resolution:
First, delete the node_modules folder in your project.
Yarn will complain about any package-lock.json files, so delete that too (or back it up, then delete it). Do not delete package.json, yarn will need that.
Simply install yarn: npm i yarn (you could do this globally, too).
Then run yarn install in your project directory.
Reading through this GitHub issue, it appears my interpretation of the error message was correct, and that this is in fact a bug in npm.
This appears to have been reported as npm/cli/issues/3083; a fix has been merged, so I guess we just have to wait until it gets included in some upcoming npm release.
I am having problems building a fresh NativeScript-Vue app in a monorepo project. GitHub repo here.
Situation
I would like to share some codes between a Vue.js web app and a NativeScript-Vue native app using yarn workspace. I have seen some NativeScript Slack posts that suggests using yarn workspace. From what I understand, code-sharing by nativescript-vue-cli-plugin is no longer an option here.
In the GitHub repo, I created packages/common, packages/web and packages/native and started a fresh vue proj in web and a fresh NS-Vue proj in native.
Problem
I was able to run web app inside web folder by running npm run serve but not NativeScript app in native folder by running ns run ios. Error suggests that symlink isn't working for the unpublished package:
% tns run ios
Error while loading nativescript-cloud is: Default commands should be required before child commands
Searching for devices...
npm ERR! code ETARGET
npm ERR! notarget No matching version found for common#1.0.0.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'native'
npm ERR! notarget
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mm/.npm/_logs/2020-10-16T05_08_56_467Z-debug.log
Unable to install dependencies. Make sure your package.json is valid and all dependencies are correct. Error is: Command npm failed with exit code 1
...but I have a folder named common under /node_modules, linked to /packages/common. Deleting the line "common":"1.0.0", in /packages/native/package.json allows me to build the app, but that kills the whole point of code-sharing I'm trying to achieve here.
Question
What am I doing wrong?
I've inherited a react/node/prismic application that uses shrinkwrap, and we need to update the prismic-reactjs package. That package requires higher versions of react and webpack, so I updated those in package.json too, and based on some npm dependency reading I've been roughly following these steps:
rm -fr node_modules
npm uninstall [package_name]
npm prune
npm cache clean
npm install [package_name]
npm shrinkwrap (to check missing dependencies)
npm install
npm shrinkwrap
That last shrinkwrap step shows the remaining "npm ERR! peer invalid:" statements, so I've been working my way top to the bottom of the list, and I'm now down to only three of them:
npm ERR! peer invalid: webpack#^3.1.0, required by extract-text-webpack-plugin#3.0.2
npm ERR! peer invalid: react#^15.6.1, required by react-dom#15.6.1
npm ERR! peer invalid: react#^15, required by react-router-dom#4.1.2
Uh oh- it looks like those peer dependencies need the older versions I'd had for webpack (I updated 3.12.0 -> 4.0.0) and react (I updated 15.6.1 -> 16.0.0).
Of those 3 other packages, one is deprecated so I can't upgrade it if I tried. I could try updating the other 2, but I'm not sure if this is yak shaving- is there a better way forward? Is it possible to have both/conflicting packages in use?
I'm trying to run npm install for a little ember-driven site that I've got, but it throws the following error:
npm ERR! path /Projects/Etc/Admin/cuscus/node_modules/npm/node_modules/dezalgo
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/Projects/Etc/Admin/cuscus/node_modules/npm/node_modules/dezalgo' -> '/Projects/Etc/Admin/cuscus/node_modules/npm/node_modules/.dezalgo.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mick/.npm/_logs/2018-01-09T01_18_51_322Z-debug.log
If I delete the node_modules directory completely then run npm install again it seems to work, but running it again fails.
What you can try is:
Be sure that you use cmd promt in Admin mode.
If you use VS Code, kill all node procceses. Close it and try again.
Delete package-lock.json and node-modules folder and try again.
Change the node version. For example try the old one v6.11.2
Try to do npm cache clean --force
Try to remove {package}.DELETE in ~/AppData/Roaming/npm/node_modules after the initial npm i -g {package} and retry npm i -g {package}
One of it can help. But not for sure. The status of issue with this problem is open for the moment.
https://github.com/npm/npm/issues/17444
I just had this issue when setting up a new machine. None of the cache clean/uninstall/reinstall steps worked for me.
However, I was able to resolve it by updating npm to the latest version. I had 5.6.0 installed, but using npm-windows-upgrade to install the latest version (5.7.1) cleared up the dependency issues.
See this answer for more information on upgrading npm on Windows:
https://stackoverflow.com/a/31520672/91189
This most likely happened because you updated your node version and because you probably already had this repo sitting on your machine before that particular update, the package-lock.json file whose sole purpose is to track the present and past state of your node_modules file and maintain a very updated dependency tree such that amongst entities using your code there will be consistency installing exactly the same dependencies ;
Entities using your code include
Teammates
Deployments (AWS ECS),
and Continuous integration tools like Travis CI that are running your code,
Try to delete the package-lock.json file. Run the npm install command and you should be fine.
The last thing you should try doing is deleting the missing package if you are not sure of what you are doing, it's usually better to avoid this.
Goodluck.