Unexpected end of input
The JavaScript engine reached the end of the file/string while still expecting closing characters.
Usually happens because:
- ☑ Missing closing brace }
- ☑ Missing closing bracket ]
- ☑ Incomplete JSON payload
🔍 Quick Checklist:
📊 Where this usually happens (estimated occurrence)
What is Unexpected end of input?
This error occurs when the parser reaches the very end of the file or string payload while it is still waiting for closing delimiters (like a matching curly brace, parenthesis, bracket, or quotation mark) to resolve an active block declaration.
Common Causes
- Forgetting to close a function, loop, or class block.
- Leaving arrays, objects, or string quotes unclosed.
- Incomplete JSON strings passed to JSON.parse().
Common Mistakes
- Writing long nested scripts without keeping indentation consistent, making it hard to see missing closing braces.
- Parsing incomplete network stream chunks before they fully resolve.
How to Fix
Framework-Specific Examples
Omitting the square bracket at the end of array lists.
try {
// Throws: Unexpected token ';' or end of input depending on engine
const list = [1, 2, 3;
} catch (err) {
// Parsing blocks code load
}Server Configuration Examples
Checking JSON buffers.
# Handled at parser layerBest Practices
- Standardize on automatic editor brace insertion plugins.
- Run lint formatting tools before running local servers.
Frequently Asked Questions (FAQ)
Q: What does 'end of input' mean?
It means the JavaScript engine parsed the entire file or string but reached the end of the text while still waiting for matching characters (like `}`, `]`, or `)`) to close open blocks.
Q: Why does this error point to the last line of my file?
Because the parser doesn't know you forgot a brace until it reaches the very end of the file and still hasn't found it. The missing brace could be anywhere inside the script.
Q: Can I catch this error in try-catch?
Only if it happens inside dynamic execution blocks like `eval()` or `JSON.parse()`. General syntax errors inside your source files block compilation completely, so no code runs.
Q: How do I prevent incomplete network buffers?
Verify that your API response has completed fully before executing `.json()` or parsing payload buffers.