nix-community / yarn2nix

Generate nix expressions from a yarn.lock file [maintainer=???]
GNU General Public License v3.0
123 stars 61 forks source link

yarn2nix fails with lock file generated by yarn install #142

Open disassembler opened 4 years ago

disassembler commented 4 years ago

I have to apply this patch to my yarn.lock every time it's regenerated:

diff --git i/yarn.lock w/yarn.lock
index 11ffdaf..9ad2b91 100644
--- i/yarn.lock
+++ w/yarn.lock
@@ -2030,8 +2030,8 @@ apollo-metrics@^1.0.1:
   resolved "https://registry.yarnpkg.com/apollo-metrics/-/apollo-metrics-1.0.1.tgz#07682dfb007a825ee3614a1d89dc71b78fe84637"
   integrity sha512-fSrZqzIITkvVgseVmpB5s8jiQ3Vit5EzLY0BG+cv0rKw9GWOLeteJZlDAAwfv6dIvsVrCoH/W91FaaC1k3nbEQ==
   dependencies:
-    apollo-server-plugin-base "^0.6.8"
-    apollo-tracing "^0.8.8"
+    apollo-server-plugin-base "^0.7.1"
+    apollo-tracing "^0.9.1"

 apollo-server-caching@^0.5.1:
   version "0.5.1"
@@ -2135,7 +2135,7 @@ apollo-server-express@^2.12.0:
     subscriptions-transport-ws "^0.9.16"
     type-is "^1.6.16"

-apollo-server-plugin-base@^0.6.8, apollo-server-plugin-base@^0.7.1:
+apollo-server-plugin-base@^0.7.1:
   version "0.7.1"
   resolved "https://registry.yarnpkg.com/apollo-server-plugin-base/-/apollo-server-plugin-base-0.7.1.tgz#998d035723c5993171fd5aff3dbe7d2661db1a96"
   integrity sha512-PRavvoWq7/Xufqc+qkDQg3Aqueq4QrPBFfoCFIjhkJ4n2d2YoqE3gTGccb8YoWusfa62ASMn6R47OdNuVtEbXw==
@@ -2174,7 +2174,7 @@ apollo-server-types@^0.3.1:
     apollo-server-caching "^0.5.1"
     apollo-server-env "^2.4.3"

-apollo-tracing@^0.8.8, apollo-tracing@^0.9.1:
+apollo-tracing@^0.9.1:
   version "0.9.1"
   resolved "https://registry.yarnpkg.com/apollo-tracing/-/apollo-tracing-0.9.1.tgz#c481be727550c73fda53d20d798cbe4ad67c61bd"
   integrity sha512-4wVNM6rc70XhwWxuDWrMBLaHA8NjB9pUS2sNpddQvP36ZtQfsa08XLSUxGAZT+bej+TzW26hKNtuO31RgqC9Hg==

With or without the patch, yarn install works fine, but without the patch if I try to nix-build -A cardano-graphql I get:

$ nix-build -A cardano-graphql
these derivations will be built:
  /nix/store/zpshv5smms1wkysjwx7xd16yc98dhszf-cardano-graphql-modules-1.0.0-rc.9.drv
  /nix/store/js4x28g2x1mxhzsd72aar31kay040q8n-cardano-graphql.drv
building '/nix/store/zpshv5smms1wkysjwx7xd16yc98dhszf-cardano-graphql-modules-1.0.0-rc.9.drv'...
configuring
building
'/build/yarn_home/.node-gyp/10.16.0/include' -> '/nix/store/az7ba381fqnscaddhsahnqv0rds2ikmk-nodejs-10.16.0/include'
yarn config v1.17.3
success Set "yarn-offline-mirror" to "/nix/store/a9s2s8dzm22qp7bnsdvaim8jc0gyfb95-offline".
Done in 0.02s.
yarn install v1.17.3
[1/4] Resolving packages...
warning Lockfile has incorrect entry for "apollo-server-plugin-base@^0.6.8". Ignoring it.
warning Lockfile has incorrect entry for "apollo-tracing@^0.8.8". Ignoring it.
error Couldn't find any versions for "apollo-server-plugin-base" that matches "^0.6.8" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: Couldn't find any versions for "apollo-tracing" that matches "^0.8.8" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
    at MessageError.ExtendableBuiltin (/nix/store/ipadk0j4mimivhinjzgxf20yg1pd6xq2-yarn-1.17.3/libexec/yarn/lib/cli.js:721:66)
    at new MessageError (/nix/store/ipadk0j4mimivhinjzgxf20yg1pd6xq2-yarn-1.17.3/libexec/yarn/lib/cli.js:750:123)
    at NpmResolver.<anonymous> (/nix/store/ipadk0j4mimivhinjzgxf20yg1pd6xq2-yarn-1.17.3/libexec/yarn/lib/cli.js:50596:15)
    at Generator.next (<anonymous>)
    at step (/nix/store/ipadk0j4mimivhinjzgxf20yg1pd6xq2-yarn-1.17.3/libexec/yarn/lib/cli.js:304:30)
    at /nix/store/ipadk0j4mimivhinjzgxf20yg1pd6xq2-yarn-1.17.3/libexec/yarn/lib/cli.js:315:13
builder for '/nix/store/zpshv5smms1wkysjwx7xd16yc98dhszf-cardano-graphql-modules-1.0.0-rc.9.drv' failed with exit code 1
cannot build derivation '/nix/store/js4x28g2x1mxhzsd72aar31kay040q8n-cardano-graphql.drv': 1 dependencies couldn't be built
error: build of '/nix/store/js4x28g2x1mxhzsd72aar31kay040q8n-cardano-graphql.drv' failed

This can be reproduced on yarn-lock-broken branch at https://github.com/input-output-hk/cardano-graphql

purefn commented 4 years ago

I'm running into the same thing with redux. In our package.json we have a

  "resolutions": {
    "redux": 3.7.2
  }

to fix the dependency. In the resulting yarn.lock file we have

redux@3.7.2, "redux@>=0.10 <5", redux@^3.6.0, redux@^3.7.2, redux@^4.0.0, redux@^4.0.1, redux@^4.0.4:
  version "3.7.2"
  resolved "redux___redux_3.7.2.tgz#06b73123215901d25d065be342eb026bc1c8537b"
  integrity sha512-pNqnf9q1hI5HHZRBkj3bAngGZW/JMCmexDlOxw4XagXY2o1327nHH54LoTjiPJ0gizoqPDRqWyX/00g0hD6w+A==
  dependencies:
    lodash "^4.2.1"
    lodash-es "^4.2.1"
    loose-envify "^1.1.0"
    symbol-observable "^1.0.3"

When trying to build we get

simspace-portal-modules> [1/4] Resolving packages...
simspace-portal-modules> warning Lockfile has incorrect entry for "redux@^4.0.1". Ignoring it.
simspace-portal-modules> warning Lockfile has incorrect entry for "redux@^4.0.0". Ignoring it.
simspace-portal-modules> warning Lockfile has incorrect entry for "redux@^4.0.4". Ignoring it.
simspace-portal-modules> error Couldn't find any versions for "redux" that matches "^4.0.1" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
simspace-portal-modules> info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
simspace-portal-modules> Error: Couldn't find any versions for "redux" that matches "^4.0.0" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
simspace-portal-modules> at MessageError.ExtendableBuiltin (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:721:66)
simspace-portal-modules> at new MessageError (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:750:123)
simspace-portal-modules> at NpmResolver.<anonymous> (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:50632:15)
simspace-portal-modules> at Generator.next (<anonymous>)
simspace-portal-modules> at step (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:310:30)
simspace-portal-modules> at /nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:321:13
simspace-portal-modules> Error: Couldn't find any versions for "redux" that matches "^4.0.4" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
simspace-portal-modules> at MessageError.ExtendableBuiltin (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:721:66)
simspace-portal-modules> at new MessageError (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:750:123)
simspace-portal-modules> at NpmResolver.<anonymous> (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:50632:15)
simspace-portal-modules> at Generator.next (<anonymous>)
simspace-portal-modules> at step (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:310:30)
simspace-portal-modules> at /nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:321:13
simspace-portal-modules> Error: Couldn't find any versions for "redux" that matches "^4.0.4" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
simspace-portal-modules> at MessageError.ExtendableBuiltin (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:721:66)
simspace-portal-modules> at new MessageError (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:750:123)
simspace-portal-modules> at NpmResolver.<anonymous> (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:50632:15)
simspace-portal-modules> at Generator.next (<anonymous>)
simspace-portal-modules> at step (/nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:310:30)
simspace-portal-modules> at /nix/store/70l4gnvcal045py1cmz8l57jx89xd3sh-yarn-1.22.0/libexec/yarn/lib/cli.js:321:13

If I edit the yarn.lock file to set all the redux dependencies to 3.7.2 things go much better.

purefn commented 4 years ago

I think this maybe related to the package.json created by mkYarnModules that is at the top level and contains { "private":true, "workspaces":["deps/**"]}.

When I use a different derivation that doesn't introduce this and instead just uses my projects package.json, I no longer have this problem.