yo icon indicating copy to clipboard operation
yo copied to clipboard

CLI crashes when searching for NPM generators

Open jcollum opened this issue 8 years ago • 9 comments

Never used yeoman before (on this machine/job anyway, I've used it at home). Installed it a few minutes ago. It crashed quickly:

versions:

$ yo --version && echo $PATH $NODE_PATH && node -e 'console.log(process.platform, process.versions)' && cat Gruntfile.js
1.5.0
/Users/collumj/.nvm/versions/node/v4.0.0/bin:.:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/include:/usr/X11R6/bin /usr/lib
darwin { http_parser: '2.5.0',
  node: '4.0.0',
  v8: '4.5.103.30',
  uv: '1.7.3',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  modules: '46',
  openssl: '1.0.2d' }
cat: Gruntfile.js: No such file or directory

Recreate:


$ yo
? 'Allo CDK! What would you like to do? Install a generator
? Search npm for generators: fast
HTTPError: Response code 404 (Not Found)
    at /Users/collumj/.nvm/versions/node/v4.0.0/lib/node_modules/yo/node_modules/got/index.js:106:11
    at BufferStream.<anonymous> (/Users/collumj/.nvm/versions/node/v4.0.0/lib/node_modules/yo/node_modules/got/node_modules/read-all-stream/index.js:64:3)
    at emitNone (events.js:72:20)
    at BufferStream.emit (events.js:166:7)
    at finishMaybe (/Users/collumj/.nvm/versions/node/v4.0.0/lib/node_modules/yo/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/lib/_stream_writable.js:509:14)
    at afterWrite (/Users/collumj/.nvm/versions/node/v4.0.0/lib/node_modules/yo/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/lib/_stream_writable.js:388:3)
    at afterTick (/Users/collumj/.nvm/versions/node/v4.0.0/lib/node_modules/yo/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/node_modules/process-nextick-args/index.js:11:8)
    at doNTCallback0 (node.js:407:9)
    at process._tickCallback (node.js:336:13)

jcollum avatar Nov 02 '15 20:11 jcollum

Works for me. You're probably just having connection problems.

❯ yo
? 'Allo Sindre! What would you like to do? Install a generator
? Search npm for generators: fast
? Here's what I found. Official generator → ෴
  Install one? (Use arrow keys)
❯ andy A fast and intuitive Yeoman generator for Android with great attitude! 
  deslight A Yeoman generator for lightning fast web application development 
  fastgap Scaffold out a mobile phonegap app 
  gulp-ng-fast Yeoman generator for gulp+angular+coffee+less+jade 
  jumper A Yeoman generator «Jumper» for the fast scaffolding front-end web applications 
  simplesite Simple generator for fast creating static websites 
  spa-prototype A Yeoman generator for a faster single page application development 
(Move up and down to reveal more choices)

sindresorhus avatar Nov 02 '15 20:11 sindresorhus

Nope:

$ curl -L  http://npmjs.org
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>npm</title>


  <meta http-equiv="cleartype" content="on" />

  <meta name="apple-mobile-web-app-capable" content="no">
  <meta name="description" content="npm is the package manager for javascript">
  <meta name="viewport" content="width=device-width,minimum-scale=1.0,initial-scale=1,user-scalable=yes">

...

jcollum avatar Nov 02 '15 20:11 jcollum

That's not the same. Different tool and different server.

Try again a few times and see if it's repeatable.

Are you behind a proxy or firewall of some kind?

sindresorhus avatar Nov 02 '15 21:11 sindresorhus

I bet it's because we are using a pass-through NPM repo:

$ cat ~/.npmrc
registry=http://xxx.mycompany.com/xxx/api/npm/npm-repo

I don't know why that would break your tool but that seems like the most likely culprit.

jcollum avatar Nov 02 '15 21:11 jcollum

@jcollum We don't spawn npm as the npm CLI search is just too slow. Instead we use package-json which talks directly to the npm server. It does support custom registries defined in .npmrc.

Try console.log'ing what URL is being used here: https://github.com/sindresorhus/package-json/blob/6f9a9da97f26b2d3e536ddd853de092aff478c2e/index.js#L22 (in the dependency in the node_modules folder inside yo.

sindresorhus avatar Nov 03 '15 07:11 sindresorhus

We are planning to switch from the npm search to our custom server to speed it up further: https://github.com/yeoman/yo/issues/361 That would solve your issue automagically. Someone needs to do it, though.

sindresorhus avatar Nov 03 '15 07:11 sindresorhus

Happened again today. Here's the opts object from /Users/collumj/.nvm/versions/node/v4.2.0/lib/node_modules/yo/node_modules/got/index.js:106:11

{ protocol: null,
  path: '/blacklist.json',
  retries: 5,
  slashes: true,
  auth: null,
  host: 'yeoman.io',
  port: null,
  hostname: 'yeoman.io',
  hash: null,
  search: null,
  query: null,
  pathname: '/blacklist.json',
  href: 'http://yeoman.io/blacklist.json',
  json: true,
  headers: 
   { 'user-agent': 'https://github.com/sindresorhus/got',
     'accept-encoding': 'gzip,deflate',
     accept: 'application/json' },
  method: 'GET' }
{ protocol: 'http:',
  path: '/aaa/api/npm/npm-repo/-/_view/byKeyword?startkey=[%22yeoman-generator%22]&endkey=[%22yeoman-generator%22,%7B%7D]&group_level=3',
  retries: 5,
  slashes: true,
  auth: null,
  host: 'aaa.bbb.com',
  port: null,
  hostname: 'aaa.bbb.com',
  hash: null,
  search: '?startkey=[%22yeoman-generator%22]&endkey=[%22yeoman-generator%22,%7B%7D]&group_level=3',
  pathname: '/aaa/api/npm/npm-repo/-/_view/byKeyword',
  href: 'http://aaa.bbb.com/aaa/api/npm/npm-repo/-/_view/byKeyword?startkey=[%22yeoman-generator%22]&endkey=[%22yeoman-generator%22,%7B%7D]&group_level=3',
  json: true,
  headers: 
   { 'user-agent': 'https://github.com/sindresorhus/got',
     'accept-encoding': 'gzip,deflate',
     accept: 'application/json' },
  method: 'GET' }

Stack:

HTTPError: Response code 404 (Not Found)
    at /Users/collumj/.nvm/versions/node/v4.2.0/lib/node_modules/yo/node_modules/got/index.js:106:11
    at BufferStream.<anonymous> (/Users/collumj/.nvm/versions/node/v4.2.0/lib/node_modules/yo/node_modules/got/node_modules/read-all-stream/index.js:64:3)
    at emitNone (events.js:72:20)
    at BufferStream.emit (events.js:166:7)
    at finishMaybe (/Users/collumj/.nvm/versions/node/v4.2.0/lib/node_modules/yo/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/lib/_stream_writable.js:509:14)
    at endWritable (/Users/collumj/.nvm/versions/node/v4.2.0/lib/node_modules/yo/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/lib/_stream_writable.js:519:3)
    at BufferStream.Writable.end (/Users/collumj/.nvm/versions/node/v4.2.0/lib/node_modules/yo/node_modules/got/node_modules/read-all-stream/node_modules/readable-stream/lib/_stream_writable.js:484:5)
    at IncomingMessage.onend (_stream_readable.js:490:10)
    at IncomingMessage.g (events.js:260:16)
    at emitNone (events.js:72:20)

I tried console logging on the line you asked for but it isn't hitting that line. That aaa.bbb.com is our local npm repo (changed the URL to hide our operations details). It seems very likely that our npm repo doesn't support something that your app is relying on. I'm saying it's probably our fault.

jcollum avatar Nov 10 '15 19:11 jcollum

I just tried to search for an angular generator and hit this error again. I had forgotten about it! Do you have any suggestions?

jcollum avatar Dec 10 '15 17:12 jcollum

@eddiemonge is working on https://github.com/yeoman/yo/issues/361 which will fix your problem.

sindresorhus avatar Dec 10 '15 18:12 sindresorhus