Skip to content

Loading…

Server not returning some of the files at random #402

Closed
ews opened this Issue · 16 comments

8 participants

@ews

yeoman server (on a new project)

Tons of this on the console

TypeError: Cannot read property 'server' of undefined
at Object.inject (/usr/local/lib/node_modules/yeoman/tasks/server.js:408:28)
at next (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:190:15)
at Function.app.handle (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:198:3)
at Server.app (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/connect.js:60:31)
at Server.EventEmitter.emit (events.js:91:17)
at HTTPParser.parser.onIncoming (http.js:1795:12)
at HTTPParser.parserOnHeadersComplete as onHeadersComplete
at Socket.socket.ondata (http.js:1692:22)
at TCP.onread (net.js:403:27)
at process.startup.processMakeCallback.process._makeCallback (node.js:248:20)

Line 408 of server.py is var port = res.socket.server.address().port;

Some files not being delivered (output from webkit console)

Request URL:http://localhost:3501/scripts/vendor/bootstrap/bootstrap-carousel.js
Request Method:GET
Status Code:500 Internal Server Error
Request URL:http://localhost:3501/scripts/vendor/bootstrap/bootstrap-button.js
Request Method:GET
Status Code:500 Internal Server Error
[.....] (all in the bootstrap dir, which has correct permissions

Also, when accessing the url individually I can see the files, so this can be related to livereload.js / websockets (?)

@addyosmani
Yeoman member

Could you describe which options you included when running yeoman init?

@thvd

I have the same problem as well, and I had all options included.

@TylerShaw

Same issue here, and chrome is returning error 500s on all the JS files except for jquery

osx 10.8.2
yeoman v0.9.0
yeoman init y,y,n,n,n

@thvd

I'm using Ubuntu as my OS:

Linux 3.2.0-30-generic #48-Ubuntu SMP Fri Aug 24 16:52:48 UTC 2012 x86_64 GNU/Linux
@everpointer

Same here!
osx 10.8.1
yeoman v0.9.0
option: yeoman init ember

work well on apache!

@TylerShaw

Any update on this?? I'm still having the same issue

@TylerShaw

in chrome I am getting
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:3501/scripts/vendor/cf69c6f2.modernizr.min.js but going to that address it loads fine
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:3501/scripts/8ab52a5b.plugins.js same result with this one.

In terminal I am getting

Running "watch" task
Waiting...TypeError: Cannot read property 'server' of undefined
    at Object.inject (/usr/local/lib/node_modules/yeoman/tasks/server.js:408:28)
    at next (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:198:3)
    at Server.app (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/connect.js:60:31)
    at Server.EventEmitter.emit (events.js:91:17)
    at HTTPParser.parser.onIncoming (http.js:1793:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
    at Socket.socket.ondata (http.js:1690:22)
    at TCP.onread (net.js:403:27)
TypeError: Cannot read property 'server' of undefined
    at Object.inject (/usr/local/lib/node_modules/yeoman/tasks/server.js:408:28)
    at next (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:198:3)
    at Server.app (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/connect.js:60:31)
    at Server.EventEmitter.emit (events.js:91:17)
    at HTTPParser.parser.onIncoming (http.js:1793:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
    at Socket.socket.ondata (http.js:1690:22)
    at TCP.onread (net.js:403:27)```

@mklabs

@sindresorhus It seems that we have an issue on the res.socket.server.adress().port, but it's inconsistent. Most of time it's okay, then on some request we get this issue. If I recall correctly, we need to do this because of the randomized port, internally handled by connect.

@TylerShaw Just to check, it would be great if you can try moving that var port = res.socket.server.address().port;, right after this few lines: https://github.com/yeoman/yeoman/blob/travis/cli/tasks/server.js#L423-425. It won't help us understand why we get randomly an undefined res.socket, but at least it should debug you through (and would give us some pointers).

@TylerShaw

HA! @mklabs You are a genius! that fixed it.

 return function inject(req, res, next) {


      // build filepath from req.url and deal with index files for trailing `/`
      var filepath = req.url.slice(-1) === '/' ? req.url + 'index.html' : req.url;

      // if ext is anything but .html, let it go through usual connect static
      // middleware.
      if ( path.extname( filepath ) !== '.html' ) {
        return next();
      }
      var port = res.socket.server.address().port;
      // setup some basic headers, at this point it's always text/html anyway
      res.setHeader('Content-Type', connect.static.mime.lookup(filepath));

      // can't use the ideal stream / pipe case, we need to alter the html response
      // by injecting that little livereload snippet
      filepath = path.join(opts.base, filepath.replace(/^\//, ''));
      fs.readFile(filepath, 'utf8', function(e, body) {
        if(e) {
          // go next and silently fail
          return next();
        }

        body = body.replace(/<\/body>/, function(w) {
          return [
            "<!-- yeoman livereload snippet -->",
            "<script>document.write('<script src=\"http://'",
            " + (location.host || 'localhost').split(':')[0]",
            " + ':" + port + "/livereload.js?snipver=1\"><\\/script>')",
            "</script>",
            "",
            w
          ].join('\n');
        });
@mklabs

haha glad it helped you out.

We still need to figure out why we get that nasty undefined error.

@paulirish paulirish added a commit that referenced this issue
@paulirish paulirish Merge branch 'master' of github.com:yeoman/yeoman
* 'master' of github.com:yeoman/yeoman:
  Adding server fix for #422, #402
b1bdcab
@TylerShaw

Annnnnddddd you guys are awesome. Thanks!

@thvd

Indeed! But how can i use this fix? Should I wait until Yeoman v1.0 will be released?

@sindresorhus
Yeoman member

This should be fixed in 0.9.1 which is going to be released very soon.

@TylerShaw

when i do git pull now, the install.sh file is what the audit.sh file was a few hours ago, and doesn't install anything, just tells you what you have installed and don't have installed. Was this on purpose?

I'm putting this in this thread because I was trying to see if the changes that were made from this thread were merged yet.

@jorgeramirez

Yes. The install.sh has changed, it now audits you on what you need to install in order to start using yeoman see #400 for the discussion that was going on about this.

@thvd

Thanks guys for the good work, it's working :)

@szinya szinya pushed a commit to menthainternet/yeoman that referenced this issue
@addyosmani addyosmani Adding server fix for #422, #402 c1455b6
@paulirish paulirish added a commit that referenced this issue
@paulirish paulirish Merge branch 'master' of github.com:yeoman/yeoman
* 'master' of github.com:yeoman/yeoman:
  Adding server fix for #422, #402
3caaeb1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.