question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"RangeError: Maximum call stack size exceeded" (urlencode) / "SyntaxError: Unexpected token" (json)

See original GitHub issue

Hello. I have this code:

var express = require("express")
var bp = require("body-parser")
var app = express()
var bpurle= app.use(bp.urlencoded({ extended: false }))
var bpjson= app.use(bp.json())
app.post("/urle", bpurle, function(req, res) {
    if (req.body === undefined) {return(console.log("There aren't any data"))}
    console.log("Received data via URL-Encode:\n" + req.body)
})
app.post("/json", bpjson, function(req, res) {
    if (req.body === undefined) {return(console.log("There aren't any data"))}
    console.log("Received data via JSON:\n" + JSON.stringify(req.body,null,2))
})
app.listen(4000)

When I execute…

curl -X POST http://127.0.0.1:4000/urle -d "data1=value1&data2=1234"

…I get this error:

RangeError: Maximum call stack size exceeded
    at next (/home/q2dg/node_modules/express/lib/router/index.js:168:16)
    at next (/home/q2dg/node_modules/express/lib/router/route.js:100:14)
    at Layer.handle_error (/home/q2dg/node_modules/express/lib/router/layer.js:54:12)
    at next (/home/q2dg/node_modules/express/lib/router/route.js:108:13)
    at /home/q2dg/node_modules/express/lib/router/index.js:603:15
    at next (/home/q2dg/node_modules/express/lib/router/index.js:246:14)
    at next (/home/q2dg/node_modules/express/lib/router/route.js:100:14)
    at Layer.handle_error (/home/q2dg/node_modules/express/lib/router/layer.js:54:12)
    at next (/home/q2dg/node_modules/express/lib/router/route.js:108:13)
    at /home/q2dg/node_modules/express/lib/router/index.js:603:15

When I execute…

curl -X POST http://127.0.0.1:4000/json -d "{'data1':'value1','data2':'1234'}" -H "Content-Type:application/json"

…I get this error:

SyntaxError: Unexpected token '
    at Object.parse (native)
    at parse (/home/q2dg/node_modules/body-parser/lib/types/json.js:76:17)
    at /home/q2dg/node_modules/body-parser/lib/read.js:98:18
    at IncomingMessage.onEnd (/home/q2dg/node_modules/body-parser/node_modules/raw-body/index.js:136:7)
    at IncomingMessage.g (events.js:199:16)
    at IncomingMessage.emit (events.js:104:17)
    at _stream_readable.js:907:16
    at process._tickCallback (node.js:372:11)

Thanks!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
dougwilsoncommented, Jan 20, 2015

Ok, I see. you created a circular dependency. You just need to remove the two app.use() statements to make your server look like this:

var express = require("express")
var bp = require("body-parser")
var app = express()
var bpurle= bp.urlencoded({ extended: false })
var bpjson= bp.json()
app.post("/urle", bpurle, function(req, res) {
    if (req.body === undefined) {return(console.log("There aren't any data"))}
    console.log("Received data via URL-Encode:\n" + req.body)
})
app.post("/json", bpjson, function(req, res) {
    if (req.body === undefined) {return(console.log("There aren't any data"))}
    console.log("Received data via JSON:\n" + JSON.stringify(req.body,null,2))
})
app.listen(4000)
0reactions
dougwilsoncommented, Jan 20, 2015

It’s no problem, I didn’t even notice it at first, which is why I wanted to confirm that was your server’s code before I ran it myself to figure it out 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Maximum call stack size exceeded error
It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you...
Read more >
JavaScript Error: Maximum Call Stack Size Exceeded
This error is a RangeError. A RangeError typically means an error has occurred outside of a code's argument value for its parameter. Now...
Read more >
How to Fix SyntaxError: Unexpected token < in JSON at ...
To fix this error you need to figure out why you're getting HTML (or something else) instead of the JSON you expected. To...
Read more >
How to fix: "RangeError: Maximum call stack size exceeded"
A "RangeError: Maximum call stack size exceeded" is an error that occurs when a function or operation tries to execute too many nested...
Read more >
SyntaxError: Unexpected token in JSON at position 0
[00:52:51] build prod failed: Unexpected token in JSON at position 0 ... Angular CLI - Module build failed: RangeError: Maximum call stack size...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found