I got 3 dependencies on my project, when I run npm update it doesn't update the version of one dependency (axios).
Here is my package.json file:
{
...
"dependencies": {
"axios": "^0.25.0",
"date-fns": "^2.26.0",
"lodash": "^4.17.15"
}
}
When I enter the npm update or npm update --save command, this is my actual result:
{
...
"dependencies": {
"axios": "^0.25.0",
"date-fns": "^2.29.1",
"lodash": "^4.17.21"
}
}
As I can see, the axios package doesn't get updated.
My expected result is to get the axios package at version 0.27.2 (latest at this day).
From docs
Caret Ranges ^1.2.3 ^0.2.5 ^0.0.4
Allows changes that do not modify the left-most non-zero element in the [major, minor, patch] tuple.
Since your axios dependency is defined as ^0.25.0, with its minor version 25 being the left-most non-zero element, it will allow update to 0.25.X, but not to 0.27.0.
Either change the dependency in your package.json, or let npm do it. This should install the newest version:
npm install axios#* --save
You can use npm update -d or npm update --save-dev to update developer dependencies. (Dependencies used in development) Using npm update only would ignore the dev dependencies.
You can now use the command npm install axios and it will automatically update axios in your package.json
Related
I'm working on a project where dependencies version are not strictly fixed (using the ^), like so:
...
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
...
Now, I'd like to strictly fix all version (remove the ^) but I'd like to keep the version actually installed (and saved in yarn.lock) at the moment and write it to package.json.
For example, for react: ^16.13.1, installed version is 16.14.0.
So I'd like my package.json to be:
...
"dependencies": {
"react": "16.14.0",
"react-dom": "16.14.0"
}
...
Is there a command to do this automatically?
The solution came from npm-check-updates.
Running this command, it updates my package.json with latest minor version for all packages:
ncu -t minor -u
Then, a little yarn install to actually install these packages and you can safely remove all the ^ of your package.json.
I has been told
ESLint couldn't find the plugin "#typescript-eslint/eslint-plugin".
(The package "#typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "D:\XXX\NNN".)
It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
npm install #typescript-eslint/eslint-plugin#latest --save-dev
by ESLint. Why it's strange is the package with ESLint preset has #typescript-eslint/eslint-plugin among dependencies:
{
"name": "#yamato_daiwa/style_guides",
"dependencies": {
"#typescript-eslint/eslint-plugin": "5.19.0",
"#typescript-eslint/parser": "5.19.0",
"eslint": "8.13.0",
"eslint-plugin-node": "11.1.0"
},
"peerDependencies": {
"#typescript-eslint/eslint-plugin": "^5.18.0",
"#typescript-eslint/parser": "^5.18.0",
"eslint": "^8.13.0",
"eslint-plugin-node": "^11.1.0",
"typescript": ">=4.0.0 <4.7.0"
}
}
(I am not sure that peerDependencies are required but I must keep this question focues on one problem)
I expected that all dependencies will be automatically added to node_modules but it has not been (there is no #typescript-eslint among scope directories):
My node version is 16.3.
Update
Looks like #typescript-eslint/eslint-plugin has been added to node_modules below library with ESLint preset. I expected it will be added to directory below node_modules of the project, not below project/node_modules/#yamato-daiwa/style_guides/node_modules.
Do you really need eslint-plugin as a peerDependency in your project?
If so, inspect that you're trying to install the same version of eslint-plugin as the lib that is requiring it.
If not, remove it.
according to documentation: "When a dependency is listed in a package as a peerDependency, it is not automatically installed. Instead, the code that includes the package must include it as its dependency.
npm will warn you if you run npm install and it does not find this dependency."
https://flaviocopes.com/npm-peer-dependencies/
If all else fails, try running "npm ci" (clean install) rather than npm install.
I have the following dependencies in my project:
"dependencies": {
"discord.io": "^2.5.3",
"discord.js": "^12.5.3",
"ms": "^2.1.3",
"node-localstorage": "^2.2.1",
"winston": "^3.3.3",
"xmlhttprequest": "^1.8.0"
}
I wanted to upgrade these to the latest version, but if I use npm update the symbol ^ prevents for example the package discord.js to update to the version 13.1.0. I want to ignore that symbol and force it to upgrade to the latest version.
I solved this problem by removing the package from the package.json, running npm i and then reinstalling the dependency. Is there any other possibility to do this automatically for all dependencies?
My Node.js
package.json
has following dependancies
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.4",
"mongoose": "^5.3.10",
"nodemon": "^1.18.5"
},
"devDependencies": {
"eslint": "^5.8.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0"
},
I am new to JS,so I want to know if we can somehow invoke package.json without going for
npm install
for every package.
When you use the command npm install or npm i, it will install all dependencies from your package.json.
As a result you get all the dependencies listed in the package.json from the current folder
You can see the documentation concerning this command here : npm install
Welcome to JS world, I'm fairly new to JS myself but I believe there two possible solutions to your problem:
npm install multiple dependencies
It is possible to install multiple dependencies at the same time with one npm install command, you may find more information that could be helpful in the documentation.
For example:
npm install got koa fs-extra
Here I have installed all 3 of my project dependencies at once.
Pre Populate package.json
You can manually add the package dependencies in the correct format to your package.json file. You might the npm documentation on the package.json file helpful.
You then will need to run:
npm install
This will take the dependencies in the package.json file and install them into the node_modules/ directory.
I use gulp to build my javascript application. I have some dependencies declared in the package.json file, for example:
"dependencies": {
"flux": "^2.0.1",
"keymirror": "~0.1.0",
"object-assign": "^1.0.0",
"react": "^0.13.1",
"dropzone": "^4.0.1",
"lodash": "^3.6.0"
}
When I run gulp build, it always prompt me some dependency cannot be found unless I manually run npm install lodash for example.
Is there a way to have gulp run npm install automatically?
Run npm install --save-dev command to resolve all dependencies.
Here is link to documentation with --save-dev parameter description: https://docs.npmjs.com/cli/install
You require to have package.json on the root level.
Then once you have to run npm install for all the dependencies with --saveDev(development dependencies) or --save(project level dependencies).
Once this is done, for the next time only run npm install command will install dependent dependencies.
gulp-install would help for your issue. Go to NPM (node package manager) and search for "gulp-install".
The node plugin gulp-install automatically installs packages/dependencies for npm, bower, tsd, and pip. The relative configurations must be found in the gulp file stream.
Example Usage:
In your gulpfile.js:
var install = require("gulp-install");
gulp.src(["./package.json", "./bower.json"])
.pipe(install());