Yarn.lock does not update after upgrading dependency with yarn add? - npm

I upgraded one of my packages by using npm i #pulumi/akamai#latest, and I see the updated devDependency in my project's package.json, with the code below.
"devDependencies": {
"#pulumi/akamai": "^1.0.0",
.....other dependencies
}
However my yarn.lock file is unchanged, with
"#pulumi/akamai#^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/#pulumi/akamai/-/akamai-0.1.0.tgz#e6eed04448670719fd4fbc3df06023c0b61b780b"
integrity sha512-Zs44yZrULrBMEA3ezb/A4baVX3cNQlE2+yrBBR75SfkK1TmhqitarEWnM1/JOQ/z7EIJZJN8SdqE5hsvXf/ssA==
dependencies:
"#pulumi/pulumi" "^2.0.0
I've tried running yarn, yarn install, and yarn add #pulumi/akamai#latest, but none of these commands are updating my yarn.lock. How can I update the yarn.lock file?

Related

NPM 7/8 is not installing peer dependencies

I'm trying to build a repository/package for my personal ESLint config files. I have all of my configuration files built the way I would like, and now I am trying to install this package to test it.
In this scenario, I have two packages:
#me/eslint-config is the package containing my ESLint config files.
test-package is the package on/in which I am trying to install #me/eslint-config.
When I try to install the #me/eslint-config package, peer dependencies are not installed, nor are they even mentioned during the installation.
Both packages currently only reside locally on my machine, side-by-side, in the same directory:
<parent_dir>:
- eslint-config
- package.json
- ...
- test-package
- package.json
- ...
The package.json file for #me/eslint-config looks as follows:
{
...
"dependencies": {
"#typescript-eslint/parser": "5.29.0"
},
"peerDependencies": {
"eslint": "8.18.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsdoc": "39.3.3",
"eslint-plugin-prefer-arrow": "1.2.3",
"#typescript-eslint/eslint-plugin": "5.29.0"
}
...
}
I am installing this package in test-package as follows:
$> cd /path/to/test-package
$> npm i ../eslint-config --save-dev
NPM properly installs all other dependencies, including the #me/eslint-config package itself, but does not install the peerDependencies of #me/eslint-config.
This is using NPM v8.1.0.
This article seems to suggest that NPM >7 installs peer dependencies automatically. This is obviously not working for me.
Things I have already tried that have not fixed the problem:
Deleting node_modules/ and package-lock.json from test-package and reinstalling everything.
Pinning all peerDependencies versions in #me/eslint-config.
Adding all peerDependencies in #me/eslint-config as both dependencies and peerDependencies in #me/eslint-config.
tl;dr NPM isn't installing peerDependencies
I had the same error on former version of npm and as you mention, npm ^8 now install peer dependencies.
But here could be ways of fining your problem
1 : estlint is a devDependencies (A guess)
eslint should be devDependencies and not a peerDependencies.
Maybe npm doesn't accept you to install it then.
I search a bit but couldn't find any real thread discussing about this
That said, I wouldn't install it as dependencies since it will be pushed to your production build, what, I think, you do not want.
2 : Being up to date
Try it with the latest version of npm
download the latest version of npm : npm install -g npm#latest
Delet node_modules/ and package-lock.json from test-package and reinstall everything. as you did already
2 : allowJs
If eslint is an js package & you see it being installed in the node_modules folder.
Inside the tsconfig.json file, under the compilerOptions add allowJs: true and set strict: false
"compilerOptions": {
"allowJs": true,
"strict": false,
Close all your instance of vs-code
Restart & retry (No need to remove the package-lock or so)

npm not installing latest version of my package

I have created my own npm feed in Azure Artifacts. I can publish my package and use it in my applications.
In my applications, the package is referenced like this in the package.json
`"#op/breeze-helpers": "^0.1.5"`
If I now publish version 0.1.6 of my package, delete my package from node_modules and run npm i , npm installs version 0.1.5 again !
I even tried npm i --cache c:/tmp/empty-cache to make sure it was not getting the package from cache, but it ends up the same. npm keeps installing version 0.1.5
what am doing wrong, I thought with the caret, the next minor should be downloaded when running npm i ?
The package-lock.json sets your currently installed version of each package in stone, and npm will use those exact versions when running npm install.
So it will download the package versions from the package-lock.json file.
I want to be on latest version always.
You could try to set the "*" as the dependency package version.
For example:
"dependencies": {
"#types/bootstrap": "*",
"#types/jquery": "*",
"bootstrap": "*"
}
Then it will always download the latest version of the target packages.

Unable to delete dependency from package-lock.json and node_modules folder

I'm working with a particular dependency which has 2 versions, the community version and the enterprise version. They have both been installed mistakenly.
Here is what part of the dependencies section in the package.json looks like and I want to uninstall (eventually) everything but the first one. However when trying to uninstall ag-charts-community it doesn't work.
"dependencies": {
"#ag-grid-enterprise/all-modules": "^23.2.1",
"ag-charts-community": "^2.0.0",
"ag-charts-vue": "^2.0.0",
"ag-grid-community": "^23.2.1",
"ag-grid-enterprise": "^23.2.1",
"ag-grid-vue": "^23.2.1",
},
When I try to run
npm uninstall --save ag-grid-community
It deletes it from package.json, however it persists in node_modules folder and in package-lock.json. How can I delete all instances of ag-grid-community in those aforementioned areas?

How to "npm install packageX" while respecting package-lock.json

I want to update a dependency (packageX) without changing a locked dependency of that package, (packageY). In my package-lock.json, I have:
"packageX": {
"requires": {
"packageY": "1.0.0",
}
},
Each time I do "npm install packageX," I'd like to update packageX but have packageY stay on the defined version. How can I do that?
There is no way to do this, may be this link can explain better https://dev.to/saurabhdaware/but-what-the-hell-is-package-lock-json-b04
The story about package.json vs package-lock.json is tricky: npm install does not ignore package.json versions, nor does it ignore the package-lock.json. What it does is verify that the package.json and package-lock.json correspond to each other. That is, if the semver versions described in package.json fit with the locked versions in package-lock.json, npm install will use the latter completely, just like npm ci would.
Now, if you change package.json such that the versions in package-lock.json are no longer valid, your npm install will be treated as if you'd done npm install some-pkg#x.y.z, where x.y.z is the new version in the package.json for some-package.

npm install clear the react-native in node_modules

I face with a problem when try to use npm install to install redux to my react-native project. Any time I do run npm install redux --save the react-native directory inside node_modules will be cleared.
Then I use rm -rf node_modules && npm install the all react-native package does not install inside node_modules so I must re-create project.
I also try to copy & past react-redux and redux in node_modules from another project to my current react-native project. But it can't success, the error lead me to the issue on github. I followed this help and it also fail.
Some other information:
➜ npm: 5.0.3
➜ react-native-cli: 2.0.1
➜ react-native: 0.45.0
➜ package.json
{
"name": "MyProjectNAME",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.45.0",
"react-redux": "^5.0.5",
"redux": "^3.6.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-jest": "20.0.3",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2017": "^6.24.1",
"babel-preset-react-native": "1.9.2",
"jest": "20.0.4",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "react-native"
}
}
Any suggest is appreciated. Thank you
Glad you have solved this issue using a workaround way but please allow me to explain why react-native module was removed when you ran npm install redux --save.
Solution:
Move the package-lock.json out of the project folder (Don't delete it yet because you will need to inspect it later on)
Run rm -rf node_modules && npm install
Check the /node_modules and react-native should be there now
Run npm install redux (npm v5 will --save by default) to install redux without having existing modules get removed
What is package-lock.json?
There are a bunch of changes for npm v5 which you can read it here. One of them is generating package-lock.json (lockfile) whenever npm modifies /node_modules or package.json.
With package-lock.json, anyone who runs npm install (v5) will get the exact same node_modules tree that you were developing on. So, you would have to commit this file too.
Why react-native module and others were removed after running npm install somePackageName even they are defined in the package.json?
The removal happened because of your existing node modules were installed prior to npm v5. If you use npm v5 to install a module (e.g. npm install redux), you will notice three things:
package-lock.json will be generated (or updated if exists). Redux and its dependencies are saved into it.
The redux's package.json is different than node modules that were installed prior to npm v5 (some extra fields prefix with _ e.g. _from, _requiredBy, _resolved etc.).
Finally, any module installed prior to v5 will be removed which I guess due to the missing extra fields in its package.json AND does not exist in the newly generated package-lock.json.
So, running rm -rf node_modules && npm install again will not solve the issue because of the package-lock.json file (Remember only redux and its dependencies were saved to the file? You can check the old package-lock.json)
Hope this might help someone else.
Finally, I solved this problem by 2 steps:
1) Create a reactjs project and install redux
2) Copy all content of node_modules in step 1 and paste to my current react-native project.
Reload app. Everything works well.
It gets removed if you create app using yarn. If you have created the app using yarn please run yarn add react-redux instead of npm install react-redux