{"record":{"id":"22a48894847f29ea","repo":"vercel/next.js","slug":"invalid-escape-character-at-the-end","errorCode":null,"errorMessage":"Invalid escape character at the end.","messagePattern":"Invalid escape character at the end\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/lib/utils.ts","lineNumber":81,"sourceCode":" * values and escaped characters.\n * Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401\n *\n * @param input The arguments string to be tokenized.\n * @returns An array of strings with the tokenized arguments.\n */\nexport const tokenizeArgs = (input: string): string[] => {\n  let args: string[] = []\n  let isInString = false\n  let willStartNewArg = true\n\n  for (let i = 0; i < input.length; i++) {\n    let char = input[i]\n\n    // Skip any escaped characters in strings.\n    if (char === '\\\\' && isInString) {\n      // Ensure we don't have an escape character at the end.\n      if (input.length === i + 1) {\n        throw new Error('Invalid escape character at the end.')\n      }\n\n      // Skip the next character.\n      char = input[++i]\n    }\n    // If we find a space outside of a string, we should start a new argument.\n    else if (char === ' ' && !isInString) {\n      willStartNewArg = true\n      continue\n    }\n\n    // If we find a quote, we should toggle the string flag.\n    else if (char === '\"') {\n      isInString = !isInString\n      continue\n    }\n\n    // If we're starting a new argument, we should add it to the array.","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/lib/utils.ts#L63-L99","documentation":"Thrown by tokenizeArgs when parsing NODE_OPTIONS (or any args string) and a backslash escape appears as the very last character inside a quoted string with no character following it. An escape needs a character to escape, so a trailing backslash is invalid.","triggerScenarios":"The NODE_OPTIONS environment variable ends with a backslash inside a quoted value, e.g. NODE_OPTIONS='--title=\"foo\\'. The tokenizer hits the backslash at i === input.length-1.","commonSituations":"Misconstructed NODE_OPTIONS in shell scripts, Docker ENV, or CI config where a trailing backslash escapes the closing quote or is left dangling. Shell line-continuation backslashes accidentally included.","solutions":["Inspect NODE_OPTIONS and remove or fix the trailing backslash.","Ensure any backslash inside a quoted NODE_OPTIONS value escapes a real following character.","Avoid backslashes in NODE_OPTIONS unless intentionally escaping a quote/space."],"exampleFix":"# before\nexport NODE_OPTIONS='--max-old-space-size=4096 --title=\"app\\'\n# the trailing backslash is invalid\n\n# after\nexport NODE_OPTIONS='--max-old-space-size=4096 --title=\"app\"'","handlingStrategy":"validation","validationCode":"function validateArgsString(input: string): void {\n  if (/\\\\$/.test(input) || (/\\\\./.test(input) && input.endsWith('\\\\'))) {\n    // crude check; better: ensure no backslash is the final char inside a quote\n  }\n}","typeGuard":"function hasTrailingEscape(input: string): boolean {\n  // returns true if a backslash is the last char inside a quoted region\n  let inStr = false\n  for (let i = 0; i < input.length; i++) {\n    if (input[i] === '\\\\' && inStr && i === input.length - 1) return true\n    if (input[i] === '\\\\' && inStr) { i++; continue }\n    if (input[i] === '\"') inStr = !inStr\n  }\n  return false\n}","tryCatchPattern":"try {\n  tokenizeArgs(process.env.NODE_OPTIONS || '')\n} catch (e) {\n  if (e.message.includes('escape character')) {\n    console.error('Fix NODE_OPTIONS: trailing backslash detected')\n    process.exit(1)\n  }\n}","preventionTips":["Avoid trailing backslashes in NODE_OPTIONS.","Validate NODE_OPTIONS in a startup script.","Use shell line continuations outside quoted values."],"tags":["node-options","cli","env","parsing"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}