yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.44k stars 2.72k forks source link

Running `yarn add PACKAGE` doesn't add the package to `packages.json` #3586

Closed cbrwizard closed 7 years ago

cbrwizard commented 7 years ago

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.
  4. 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.

arcanis commented 7 years ago

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"
  }
}
cbrwizard commented 7 years ago

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)

bestander commented 7 years ago

Thanks for a follow-up, @cbrwizard

cmawhorter commented 6 years ago

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.

laugri commented 6 years ago

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

tlaak commented 6 years ago

I just noticed the same issue with node 9.5.0.

codemilli commented 6 years ago

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.

aguynamedben commented 5 years ago

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).

saibaneer commented 2 years ago

Hi Guys, I have this same issue. The weirdest thing is, there's no package-json.lock file. I have checked all other files, there's no hidden node_modules. grasp

faceyacc commented 2 years ago

Hi Guys, I have this same issue. The weirdest thing is, there's no package-json.lock file. I have checked all other files, there's no hidden node_modules. grasp

I believe you are following Patrick's course on Blockchain. A quick workaround is to manually add his package.json file and run npm install. Once that is done run yarn install and you should be good to go.

EngAbdalrhman commented 1 year ago

Hi Guys, I have this same issue. The weirdest thing is, there's no package-json.lock file. I have checked all other files, there's no hidden node_modules. grasp

I believe you are following Patrick's course on Blockchain. A quick workaround is to manually add his package.json file and run npm install. Once that is done run yarn install and you should be good to go.

i am following too and intalled npm firstly then yarn and added hardhat and gyp manuely but i am trying to run

yarn add --dev @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers @nomiclabs/hardhat-etherscan @nomiclabs/hardhat-waffle chai ethereum-waffle hardhat hardhat-contract-sizer hardhat-deploy hardhat-gas-reporter prettier prettier-plugin-solidity solhint solidity-coverage dotenv

but noting added to package.json , that is the output

 YN0000: ┌ Resolution step
➤ YN0061: │ debug@npm:3.2.6 is deprecated: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
➤ YN0061: │ request-promise-native@npm:1.0.9 is deprecated: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
➤ YN0061: │ uuid@npm:2.0.1 is deprecated: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which 
is known to be problematic.  See https://v8.dev/blog/math-random for details.
➤ YN0061: │ request@npm:2.88.2 is deprecated: request has been deprecated, see https://github.com/request/request/issues/3142
➤ YN0061: │ uuid@npm:3.4.0 is deprecated: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which 
is known to be problematic.  See https://v8.dev/blog/math-random for details.
➤ YN0016: │ @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers: Registry failed to return tag "hardhat-deploy-ethers"
➤ YN0000: └ Completed in 4s 207ms
➤ YN0000: Failed with errors in 4s 210ms
➤ YN0061: har-validator@npm:5.1.5 is deprecated: this library is no longer supported
➤ YN0032: fsevents@npm:2.1.3: Implicit dependencies on node-gyp are discouraged
➤ YN0061: fsevents@npm:2.1.3 is deprecated: "Please update to latest v2.3 or v2.2"
➤ YN0032: keccak@npm:3.0.2: Implicit dependencies on node-gyp are discouraged
➤ YN0032: keccak@npm:3.0.1: Implicit dependencies on node-gyp are discouraged
➤ YN0032: bufferutil@npm:4.0.5: Implicit dependencies on node-gyp are discouraged
➤ YN0032: utf-8-validate@npm:5.0.7: Implicit dependencies on node-gyp are discouraged
➤ YN0032: leveldown@npm:6.1.0: Implicit dependencies on node-gyp are discouraged
➤ YN0032: @trufflesuite/bigint-buffer@npm:1.1.10: Implicit dependencies on node-gyp are discouraged
➤ YN0032: @trufflesuite/bigint-buffer@npm:1.1.9: Implicit dependencies on node-gyp are discouraged