This is with yarn 1.0.2 and node 8.4.0 installed via FreeBSD 11 packages. In ~/tmp/test-yarn I was stumped why neither package.json nor yarn.lock files were being created with yarn init. Because pacakage.json and yarn.lock files existed in ~/, it seems yarn walked up the directory tree to find the project root and run the command from there. If this is intended behaviour, maybe it should be documented to prevent the confusion I had.
jrm@phe ~/tmp/test_yarn % yarn init --verbose
yarn init v1.0.2
verbose 0.69 Checking for configuration file "/usr/home/jrm/.npmrc".
verbose 0.69 Checking for configuration file "/home/jrm/.npmrc".
verbose 0.691 Checking for configuration file "/usr/local/etc/npmrc".
verbose 0.691 Checking for configuration file "/usr/home/jrm/.npmrc".
verbose 0.691 Checking for configuration file "/usr/home/.npmrc".
verbose 0.691 Checking for configuration file "/usr/.npmrc".
verbose 0.692 Checking for configuration file "/usr/home/jrm/.yarnrc".
verbose 0.692 Found configuration file "/usr/home/jrm/.yarnrc".
verbose 0.693 Checking for configuration file "/home/jrm/.yarnrc".
verbose 0.693 Found configuration file "/home/jrm/.yarnrc".
verbose 0.693 Checking for configuration file "/usr/local/etc/yarnrc".
verbose 0.693 Checking for configuration file "/usr/home/jrm/.yarnrc".
verbose 0.693 Found configuration file "/usr/home/jrm/.yarnrc".
verbose 0.693 Checking for configuration file "/usr/home/.yarnrc".
verbose 0.693 Checking for configuration file "/usr/.yarnrc".
verbose 0.696 current time: 2017-09-13T19:06:24.994Z
question name (test_yarn):
question version (1.0.0):
question description (Blah):
question entry point (index.js):
question repository url (none):
question author (blah):
question license (AGPL-3.0):
question private (true):
success Saved package.json
Done in 11.95s.
jrm@phe ~/tmp/test_yarn % ls -lah
total 33
drwxr-xr-x 2 jrm jrm 2B Sep 13 16:05 .
drwxr-xr-x 20 jrm jrm 54B Sep 13 13:44 ..
in NPM you can move into a sub directory and so something like npm install left-pad and it will modify the package.json in the root dir of the project (it moves back directories until it finds one)
so I assume Yarn is trying to do the same.
However with npm init it doesn't do that and makes a new nested package.json in the current dir.
I would propose that Yarn not move up the directory hierarchy for init command.
This would be a factor for workspaces as well, because nested package.json files are going to be the "normal" thing in a workspace configuration, and a change would allow a user to yarn init inside a workspace sub-project. With the way this is functioning now, a user would have to manually create package.json since yarn init would not create it in the subdirectory.
Definitely a bug. Anyone willing to submit a PR?
Hi,
I want to tackle this issue if it's okay :)
Just to be clear, is the expected behaviour for yarn init to create/modify the package.json on the current directory only?
I want to tackle this issue if it's okay :)
Yes, pleae do!
Just to be clear, is the expected behaviour for yarn init to create/modify the package.json on the current directory only?
The expected behavior for yarn is to find the package.json upwards for all commands __except__ for init. yarn init should always initialize a new project inside the current folder.
Would love to see this gets fixed!. Was experimenting with workspaces, and couldn't understand what was happening though.
I wonder if this bug has been fix? I'm having this issue on version 1.1.0.
@BYK
Yup. Just tried to run yarn init and had this issue:
➜ yarn --version
1.1.0
Experienced same issue on version 1.3.2, yarn created package.json in my home directory, not the directory I launched the command.
@OliverM please file a new issue with full reproduction details.
Most helpful comment
Yup. Just tried to run
yarn initand had this issue: