10

When I start the server on port 8080 it doesn't give me an error, but when I am trying to browse the http://localhost:8080/nowjs/now.js the server raises an error:

[RangeError: Maximum call stack size exceeded]
undefined

I tried the same with socket.io and it worked fine.

timidboy
  • 1,702
  • 1
  • 16
  • 27
  • see this http://javascriptrules.com/2009/06/30/limitation-on-call-stacks/ – andres descalzo Jun 04 '12 at 12:59
  • Could you include some code samples or even a fiddle that reproduce the problem? If you don't find the source in the process, then maybe we could spot it :) – Kato Jun 10 '12 at 04:21
  • even this simple code produces the error: `var http = require('http'); var server = http.createServer(); server.listen(8080); var nowjs = require("now"); var everyone = nowjs.initialize(server);` – timidboy Jun 13 '12 at 03:22
  • By the way, I'm running it on Ubuntu 12.04 – timidboy Jun 13 '12 at 03:26

3 Answers3

8

Hmm, if now.js uses date.js, maybe your issue lies here. What the link says is that date.js tries to set a toString to Date prototype, but when toString is already defined, you get the circular reference mentioned in the other answers.

Basically, they say that in date.js, you change

Date.prototype._toString=Date.prototype.toString

to

if(Date.prototype._toString==undefined) {Date.prototype._toString=Date.prototype.toString;}

I hope it will help someone. It helped me.

Zlatko
  • 18,936
  • 14
  • 70
  • 123
5

Aadit, have you read the following:

Maximum Call Stack Size Exceeded During a setTimeout Call

Uncaught RangeError: Maximum call stack size exceeded, JavaScript

So, as you may see the problem seems to be arising because of the an improper use of stack sizes. If you haven't already you may read a bit more about this problem in detail here along with a possible solution: Maximum call stack size exceeded error

I don't think it has anything to do with the port, more with the methods/functions in the manner you're interacting/using the stack.

Then again, I may be wrong. ;D

Community
  • 1
  • 1
Rohan Durve
  • 340
  • 2
  • 14
  • I already know about call stacks in JavaScript. What I wanted to know was why did the new version of `now.js` suddenly break existing code. – Aadit M Shah Jun 06 '12 at 03:34
  • Is this it? http://stackoverflow.com/questions/10896167/nowjs-running-node-and-nowjs-on-a-hosted-server-error-maximum-call-stack-s – Rohan Durve Jun 06 '12 at 08:07
  • Nope. Didn't work for me. I'm using node v0.6.18 which is the latest stable version. – Aadit M Shah Jun 06 '12 at 08:42
4

I've had two problems with now.js that produce this error message. Hopefully one of them will help you.

Circular References

You cannot include any circular references in objects passed into now, or it's extend method will barf. There were some optimizations and workarounds for this and it's now listed as an closed issue, but I have run into it.

initialize() only once

Second, you may not call require('now').initialize(...) twice or the two instances have a little intellectual conversation and race each other right out of the stack.

What I did instead was to create everyone in app.js and pass it into all my require(...) methods that need to reference the now "pocket".

In /app.js:

var conf = {
    everyone: require('now').initialize(app)
    port: 3000,
    // etc...
};

require('./routes')(conf)
// etc...

In routes/index.js:

module.exports = function(conf) {
   var everyone = conf.everyone;

   return {
       send: function() {
           everyone.now.clientFxn(...);
       }
   }
}
Kato
  • 40,352
  • 6
  • 119
  • 149