-->

Yeoman can't recognize a generator that was in

2019-04-19 00:24发布

问题:

I ran sudo npm install -g generator-flask and it was saved. I was able to confirm by running npm list-g.

I then run yo flask. Thinking that this was going to work, I instead get an error message:

Error flask

You don't seem to have a generator with the name flask installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 22 registered generators run yo with the `--help` option.

I do as it tells me by running yo --help and discover that the flask generator is not there.

I try this with sudo npm install -g generator-angular-flask and the problem is recreated with Angular Flask. I'm assuming this is going to happen for all the generators which is why I've titled it as Yeoman not recognizing new npm installs.

Does anyone know why this has happened?

回答1:

A workaround, but does solve the problem:

npm link generator-angular-flask

(as does just installing the module locally)



回答2:

Usually it is a $NODE_PATH issue, but rather then guessing, run:

yo doctor

and follow the instructions!



回答3:

Node path is the issue. To setup path:

export NODE_PATH=$HOME/.node/lib/node_modules/

In my case node is in HOME directory.



回答4:

I was having a similar issue. Basically Yeoman was showing No installed generators, even if I fired up yeoman and installed the generator again still no luck to run it.

I typed yo doctor and did the changes it recommends, but still no luck...

I then ran

export NODE_PATH=$HOME/.node/lib/node_modules/

Then I fired up Yeoman and still no luck.

I then decide run yo doctor again and voila! New errors. I then saw the final recommendation by the yo doctor so I decide to run it:

export NODE_PATH=$NODE_PATH:/Users/slickstyles/.npm-global/lib/node_modules

After I type yo and guess what I see? All my installed yeoman generators showing and working marvelously.



回答5:

You can use:

yo doctor

and you will not something like:

npm root value is not in your NODE_PATH                                                                                                                                                                     

[Info]                                                                                                                                                                                                      
  NODE_PATH = /home/action/.node/lib/node_modules/                                                                                                                                                          
  npm root  = /home/action/.parts/lib/node_modules                                                                                                                                                          

[Fix] Append the npm root value to your NODE_PATH variable                                                                                                                                                  
Add this line to your .bashrc                                                                                                                                                                               
    export NODE_PATH=$NODE_PATH:/home/action/.parts/lib/node_modules                                                                                                                                        
  Or run this command                                                                                                                                                                                       
    echo "export NODE_PATH=$NODE_PATH:/home/action/.parts/lib/node_modules" >> ~/.bashrc && source ~/.bashrc     

and try again:

npm install -g generator-webapp  


回答6:

Check if you have NODE_PATH set. To set it open a terminal and type (assuming you have node under /opt/node/ and use bash shell)

echo "export NODE_PATH=/opt/node:/opt/node/lib/node_modules" >> ~/.bashrc && . ~/.bashrc 

Once done, run yo doctor. If all is ok, run yo to see your installed generators.



标签: npm yeoman