yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Moving package form devDependencies to dependencies does not change the yarn.lock

Open akayami-legacy opened this issue 8 years ago • 5 comments

Do you want to request a feature or report a bug? bug What is the current behavior? In package.json, if I put a package "merge": "^1.2.0" in "devDependencies", generate a yarn.lock, if I move the package from "devDependencies" to "dependencies" and rerun yarn install, the lock file does not change. Subsequently the merge package will not be installed if yarn install --production is executed.

If the current behavior is a bug, please provide the steps to reproduce. See above

What is the expected behavior? Merge package should be installed since the dependency moved from dev to regular.

Please mention your node.js, yarn and operating system version. node v9.3.0, yarn 1.3.2, arch linux.

akayami-legacy avatar Dec 14 '17 14:12 akayami-legacy

The lockfile does not track where the dependency came from (dependencies vs devDependencies) so has no reason to change.

Confirmed install problem on v1.3.2

~/Projects/yarn-test 🐒   cat package.json
{
  "name": "yarn-test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "merge": "^1.2.0"
  }
}

~/Projects/yarn-test 🐒   yarn install --production
yarn install v1.3.2
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
✨  Done in 0.10s.

~/Projects/yarn-test 🐒   ls node_modules/


(then edit package.json)

~/Projects/yarn-test 🐒   cat package.json
{
  "name": "yarn-test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "merge": "^1.2.0"
  }
}

~/Projects/yarn-test 🐒   yarn install --production
yarn install v1.3.2
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.09s.

~/Projects/yarn-test 🐒   ls node_modules/

As a workaround, deleting node_modules/.yarn-integrity causes the package to be installed.

~/Projects/yarn-test 🐒   rm node_modules/.yarn-integrity

~/Projects/yarn-test 🐒   yarn install --production
yarn install v1.3.2
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
✨  Done in 0.10s.

~/Projects/yarn-test 🐒   ls node_modules/
merge

rally25rs avatar Dec 14 '17 15:12 rally25rs

I took a dive into the code and have created a test for this bug. A maintainer should correct me here but I don't think there is an easy fix for this problem. Since yarn does not keep a record of which modules are actually installed, there is no way to know if a dependency moved from dev to non-dev apart from walking down the directory tree.

The options seem to be:

  • store dev/not dev in the .yarn-integrity file Will probably be the cleanest but requires a major change in the file's format which might be a hassle
  • do not include dev dependencies in .yarn-integrity > lockfileEntries when installing with --production flag. This should cause an update when dependencies are moved since new entries will cause a mismatch. IMO this seems the best approach although I don't have extensive knowledge of the effects of this change
  • walk the directory tree (slowest, not recommended)

MatthiasKunnen avatar Jun 20 '20 04:06 MatthiasKunnen

Any updates on this issue? I'm having the same problem. The way I fixed it is by running:

yarn remove <packages>,

Then:

yarn add <packages>

It's a primitive way and has to redownload the packages so could take some while if you are moving a lot. As mentioned, changing package.json does nothing and doesn't install the files.

Skaytacium avatar Jan 11 '21 09:01 Skaytacium

Closing as fixed in v2

https://yarnpkg.com/getting-started/migration

merceyz avatar Jan 11 '21 09:01 merceyz

For those who came from any search engine and found this, we found another workaround by changing something in package version in package.json. This forces yarn to update (or downgrade) package.

lilacdev avatar Aug 30 '21 15:08 lilacdev