yo angular generates files in wrong path ( home di

2019-03-18 04:05发布

问题:

yo angular generates the files in my home directory and I don't know why.

I did the following:

ppa for node

curl -sL https://deb.nodesource.com/setup | sudo bash -

then install node

sudo apt-get install -y nodejs

create a symlink

sudo ln -s "$(which nodejs)" /usr/bin/node

install yeoman

sudo npm install -g yo
sudo npm install -g generator-angular

next steps from the instruction from https://github.com/yeoman/generator-angular

mkdir my-new-project && cd $_

now I run

yo angular test1

now all the files will be created in my home directory instead of the my-new-project directory where I am currently. What did I wrong?

node -v: v0.10.36

npm -v: 2.5.1

Update1: new npm version

Solution:

yo angular looks for .yo-rc.json file in the current directory, if the file isnt there it tries to find it in the home dir. To solve this:

look for a hidden .yo-rc.json file in the home directory and delete it. Or create an empty .yo-rc.json file in the directory you want to use.

回答1:

Thanks to issue page at https://github.com/yeoman/generator-angular/issues/1037#issuecomment-83118093 the solutions was relatively easy.

After the command mkdir my-new-project && cd $_ I needed to create an empty .yo-rc.json file with {} as content to this folder.

Then I could start yo and all files are created in my my-new-project folder now.



回答2:

In case anyone else stumbles on this. The reason will be that a .yo-rc.json file is in the "wrong" directory.

Delete it and all will be well.



回答3:

This started happening to me after I ran yo from my home folder by mistake. Apparently I didn't clean up the generated files properly and left the ~/.yo-rc.json around. All you need to do is get rid of the .yo-rc.json in your home folder and run yo from your desired folder again.



回答4:

Probably you have there .yo-rc.json file. You should delete all hidden files in home directory which yeoman created and it's should works.



回答5:

you should try not to install node with sudo, that causes your troubles. Take one instruction out of this link to install your node for usual user Instructions and it should work.



回答6:

I searched for .yo-rc.json file in the folder it wrongfully creates your project in, then showed all hidden files via "defaults write com.apple.finder AppleShowAllFiles YES" in terminal then reload Finder ( alt button + right click on finder icon) and deleted the hidden .yo-rc.json file and other hidden files that came with it. Then reloaded finder again after using the same command as above but replace YES by NO. That did it for me !