Yarn: Running `yarn add PACKAGE` doesn't add the package to `packages.json`

Created on 6 Jun 2017  ยท  8Comments  ยท  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

Bug
What is the current behavior?
Running yarn add PACKAGE doesn't add the package to packages.json

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

  1. cd to a folder with yarn.lock, package.json
  2. run yarn add koa-helmet (or any other package)
  3. It outputs
success Saved lockfile.
success Saved 1 new dependency.
  1. No updates in package.json

What is the expected behavior?
Expect package.json to be updated with

    "koa-helmet": "^3.2.0",

Please mention your node.js, yarn and operating system version.

โฏ node -v
v8.0.0
โฏ yarn -V
0.24.6
โฏ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.12.5
BuildVersion:   16F73

The funny thing is that running npm i -S koa-helmet from the exact same folder worked as expected: it added a new line to package.json.

Noticed today, spent some time trying to understand why didn't my Node couldn't find a package even though I have installed it hehe.
My theory is that it might be linked with a node upgrade, which I did yesterday.
Tried with reinstalling yarn using brew, got the same result.

needs-repro-script

Most helpful comment

I think I figured out the problem here: node-gyp. If your package.json has a dep that requires node-gyp and node-gyp doesn't exist, yarn will say it worked -- but doesn't -- and package.json won't be updated.

In my case, this dep was canvas-prebuilt.

In the yarn output, yarn was complaining about node-gyp command not found when running with my hombrew-installed-nodejs. No idea why no node-gyp, but switching to nvm use 8 (8.0.0) resolved the problem.

Yarn finds node-gyp and all is once again right with the world.

All 8 comments

Cannot reproduce :(

โฏ [mael-mbp?] /Users/mael/test โฏ rm -rf package.json node_modules && echo '{}' > package.json && yarn && yarn add koa-helmet && cat package.json

yarn install v0.23.4
info No lockfile found.
warning No license field
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
[4/4] ๐Ÿ“ƒ  Building fresh packages...

success Saved lockfile.
โœจ  Done in 0.05s.
yarn add v0.23.4
warning No license field
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
[3/4] ๐Ÿ”—  Linking dependencies...
[4/4] ๐Ÿ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 33 new dependencies.
warning No license field
โœจ  Done in 1.30s.
{
  "dependencies": {
    "koa-helmet": "^3.2.0"
  }
}

Just wanted to add that now this works as expected for me. I don't know what caused this (a theory is that Docker's volume prevented package.json from being updated, but I don't want to check it now)

Thanks for a follow-up, @cbrwizard

I think I figured out the problem here: node-gyp. If your package.json has a dep that requires node-gyp and node-gyp doesn't exist, yarn will say it worked -- but doesn't -- and package.json won't be updated.

In my case, this dep was canvas-prebuilt.

In the yarn output, yarn was complaining about node-gyp command not found when running with my hombrew-installed-nodejs. No idea why no node-gyp, but switching to nvm use 8 (8.0.0) resolved the problem.

Yarn finds node-gyp and all is once again right with the world.

I had the same issue as @cmawhorter. Updating node from v8.6.0 to v8.9.4 fixed it for me.

I just noticed the same issue with node 9.5.0.

When I use node version v9.8.0, I noticed yarn does not add any info in package.json.
So I change node version to v8.10.0 and it just works.

Just noticed this using Node v10.2.0 and node-sqlcipher, a library that also depends on node-gyp. Everything looked fine, but node_modules/ was not added, and the package was not added to package.json.

Seems like a bug with node-gyp. Once I added node-gyp as a dev dependency myself, in my own project, everything started working (i.e. yarn add --dev node-gyp).

Was this page helpful?
0 / 5 - 0 ratings