yeoman / yo

CLI tool for running Yeoman generators
http://yeoman.io
BSD 2-Clause "Simplified" License
3.85k stars 400 forks source link

yo always lookup generator from system folders #532

Open jchip opened 7 years ago

jchip commented 7 years ago

Type of issue

bug

Note: I am not sure if the behavior is intended, but the effect is causing a log of confusion.

If the behavior is intended, then it would help if yo displays info about where each generator is coming from.


My environment

Expected behavior

When I use nvm to switch my NodeJS to another version, yo should lookup generators only under that version's node_modules.

Current behavior

If I installed NodeJS globally on my system and installed a generator with that, then it goes to /usr/local/lib/node_modules/, but when I use nvm to switch to another Node binary under ~/.nvm, yo continue to load generators from /usr/local/lib/node_modules.

Updated: To make matter even more confusing, when you use the "Update generator" feature in yo, it actually uses npm to update the generator that's under nvm.

Steps to reproduce the behavior

  1. Install NodeJS globally
  2. npm i -g yo generator-node
  3. Install nvm and switch to a NodeJS installed with nvm
  4. npm i -g yo generator-node
  5. yo node

yo node still use the generator in step 2.

Command line output

Paste your error output over here
SBoudrias commented 7 years ago

When you run yo, it's running the yo binary (not the nvm node). In order to run it, your OS will use a Node version that may be different from your nvm one.

I think you should check in the nvm issue list about that, someone else probably run into this issue before. Maybe something prevents it from registering the specified Node version as the OS defaults.

jchip commented 7 years ago

@SBoudrias thanks for pointing that out, I verified that is not what's happening.

L-SB8H1M2G8W-M:~ xchen11$ which node
/Users/xchen11/.nvm/versions/node/v6.11.1/bin/node
L-SB8H1M2G8W-M:~ xchen11$ which npm
/Users/xchen11/.nvm/versions/node/v6.11.1/bin/npm
L-SB8H1M2G8W-M:~ xchen11$ node -v
v6.11.1
L-SB8H1M2G8W-M:~ xchen11$ npm -v
3.10.10
L-SB8H1M2G8W-M:~ xchen11$ head -5 /usr/local/lib/node_modules/generator-node/generators/app/index.js 
'use strict';

console.log("generator-node __dirname", __dirname);
const _ = require('lodash');
const extend = _.merge;
L-SB8H1M2G8W-M:~ xchen11$ head -5 /Users/xchen11/.nvm/versions/node/v6.11.1/lib/node_modules/generator-node/generators/app/index.js 
'use strict';
console.log("generator-node __dirname", __dirname);

const _ = require('lodash');
const extend = _.merge;
L-SB8H1M2G8W-M:~ xchen11$ head -5 /Users/xchen11/.nvm/versions/node/v6.11.1/bin/yo
#!/usr/bin/env node

console.log("yo __dirname", __dirname);
console.log("yo process.execPath", process.execPath);
'use strict';
L-SB8H1M2G8W-M:~ xchen11$ yo node
yo __dirname /Users/xchen11/.nvm/versions/node/v6.11.1/lib/node_modules/yo/lib
yo process.execPath /Users/xchen11/.nvm/versions/node/v6.11.1/bin/node
generator-node __dirname /usr/local/lib/node_modules/generator-node/generators/app
? Module Name (xchen11) 
L-SB8H1M2G8W-M:~ xchen11$ 
SBoudrias commented 7 years ago

This doesn't prove that. If you open a new terminal tabs and check which node, you won't have the same given nvm work on a per process basis.

jchip commented 7 years ago

Removed the #!/usr/bin/env node#!/usr/bin/env node line from yo, and run everything with explicit full path:

L-SB8H1M2G8W-M:~ xchen11$ head -5 /Users/xchen11/.nvm/versions/node/v6.11.1/bin/yo

console.log("yo __dirname", __dirname);
console.log("yo process.execPath", process.execPath);
'use strict';
const fs = require('fs');
L-SB8H1M2G8W-M:~ xchen11$ which node
/Users/xchen11/.nvm/versions/node/v6.11.1/bin/node
L-SB8H1M2G8W-M:~ xchen11$ /Users/xchen11/.nvm/versions/node/v6.11.1/bin/node /Users/xchen11/.nvm/versions/node/v6.11.1/bin/yo node
yo __dirname /Users/xchen11/.nvm/versions/node/v6.11.1/lib/node_modules/yo/lib
yo process.execPath /Users/xchen11/.nvm/versions/node/v6.11.1/bin/node
generator-node __dirname /usr/local/lib/node_modules/generator-node/generators/app
? Module Name (xchen11) 
L-SB8H1M2G8W-M:~ xchen11$ 
jchip commented 7 years ago

Also, I have nvm setup in my .bashrc file so if I open a new terminal tab, it sets up node in my new shell automatically.

SBoudrias commented 7 years ago

Any chance which yo was pointing to a global install not under the nvm folder?

jchip commented 7 years ago

By invoking yo with explicit full paths, it wouldn't matter.

/Users/xchen11/.nvm/versions/node/v6.11.1/bin/node /Users/xchen11/.nvm/versions/node/v6.11.1/bin/yo

But which yo is pointing to the one under nvm:

L-SB8H1M2G8W-M:~ xchen11$ which yo
/Users/xchen11/.nvm/versions/node/v6.11.1/bin/yo