Open jchip opened 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.
@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$
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.
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$
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.
Any chance which yo
was pointing to a global install not under the nvm folder?
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
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
Darwin L-SB8H1M2G8W-M.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
6.11.1
3.10.10
2.0.0
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
npm i -g yo generator-node
npm i -g yo generator-node
yo node
yo node
still use the generator in step 2.Command line output