zloirock/core-js · error · SyntaxError
Failed to parse number's exponent value at: ${i}
Error message
Failed to parse number's exponent value at: ${i} What it means
This SyntaxError is thrown by core-js's polyfilled JSON.parse when a number contains an 'e' or 'E' exponent marker but no digits follow it (after an optional sign). JSON requires at least one exponent digit, so inputs like '1e', '2e+' are invalid and parsing stops at the reported index.
Source
Thrown at packages/core-js/modules/es.json.parse.js:218
number: function () {
var source = this.source;
var startIndex = this.index;
var i = startIndex;
if (at(source, i) === '-') i++;
if (at(source, i) === '0') i++;
else if (exec(IS_NON_ZERO_DIGIT, at(source, i))) i = this.skip(IS_DIGIT, i + 1);
else throw new SyntaxError('Failed to parse number at: ' + i);
if (at(source, i) === '.') {
var fractionStartIndex = i + 1;
i = this.skip(IS_DIGIT, fractionStartIndex);
if (fractionStartIndex === i) throw new SyntaxError("Failed to parse number's fraction at: " + i);
}
if (at(source, i) === 'e' || at(source, i) === 'E') {
i++;
if (at(source, i) === '+' || at(source, i) === '-') i++;
var exponentStartIndex = i;
i = this.skip(IS_DIGIT, i);
if (exponentStartIndex === i) throw new SyntaxError("Failed to parse number's exponent value at: " + i);
}
return this.node(PRIMITIVE, Number(slice(source, startIndex, i)), startIndex, i);
},
keyword: function (value) {
var keyword = '' + value;
var index = this.index;
var endIndex = index + keyword.length;
if (slice(this.source, index, endIndex) !== keyword) throw new SyntaxError('Failed to parse value at: ' + index);
return this.node(PRIMITIVE, value, index, endIndex);
},
skip: function (regex, i) {
var source = this.source;
for (; i < source.length; i++) if (!exec(regex, at(source, i))) break;
return i;
},
until: function (array, i) {
i = this.skip(IS_WHITESPACE, i);
var chr = at(this.source, i);View on GitHub (pinned to 84e45fba09)
Solutions
- Fix the source so the exponent marker is always followed by digits ('1e' -> '1e0', '3E-' -> '3E-1') or remove the marker
- Validate numeric strings with a regex like /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/ before embedding them in JSON
- Build payloads with JSON.stringify on real numbers instead of manual string templates
- Use the reported index to find and inspect the malformed token in the payload
- Wrap JSON.parse in try/catch to convert the SyntaxError into an application-level parse failure with context
Example fix
// before
JSON.parse('{"n": 1e}'); // SyntaxError: Failed to parse number's exponent value at: 9
// after
JSON.parse('{"n": 1e0}'); Defensive patterns
Strategy: validation
Validate before calling
// validate exponent-bearing numeric strings before use
function isValidExponent(numStr) {
return /^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(numStr) && !/[eE][+-]?$/.test(numStr);
} Try / catch
try {
return JSON.parse(input);
} catch (e) {
if (e instanceof SyntaxError && /exponent value/.test(e.message)) {
throw new Error('JSON number has exponent marker without digits: ' + e.message);
}
throw e;
} Prevention
- Ensure exponent variables are never empty/undefined in templates: `${m}e${Number(exp) || 0}`
- Validate numeric strings against the JSON number grammar before embedding
- Guard against truncation of scientific-notation output
- Prefer JSON.stringify for all numeric serialization
When it happens
Trigger: JSON.parse on text containing a number with a dangling exponent, e.g. '{"n": 1e}', '3E-', '5e+,'; caused by truncation or by string-building code that appends 'e' + possibly-empty variable.
Common situations: Truncated scientific-notation output from logs or streams; constructing payloads with `"v": ${mantissa}e${exp}` where exp is empty/undefined; hand-edited data files; legacy engines running the core-js JSON.parse polyfill.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse number at: ${i}
- Failed to parse number's fraction at: ${i}
- Failed to parse value at: ${index}
- String should only contain hex characters
- Unexpected extra character: "${chr}" after the parsed data a
AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30).
Data as JSON: /api/errors/d6d928d4124bb27f.
Report an issue: GitHub.