Fixes · Checked on 2026-10-07, with Node.js 24
SyntaxError: Invalid or unexpected token
A character JavaScript can't read: often a string broken across lines, or a curly quote.
The error
$ node app.js
C:\work\app\app.js:1
const lines = items.join('
^
SyntaxError: Invalid or unexpected token
The line and the caret show where Node gave up.
Why it happens
A string that runs onto the next line. A string in ' or " quotes
ends with its line, so a real line break inside it is an error. (Strings in backticks may span lines.) Coding
agents cause this when they patch a JavaScript file from a Python script: in an ordinary Python string,
\n is a line break, so writing join('\n') into the file puts a real line break
between the quotes.
src.replace("join(', ')", "join('\n')") # writes join(' and a line break
Curly quotes. ‘DMN’ or “DMN”, pasted from a document or a chat,
aren't quotes to JavaScript, and give the same error.
The fix
In the Python script, a raw string writes the two characters \n, as JavaScript expects:
src.replace("join(', ')", r"join('\n')")
Or edit the file with an edit tool, which writes exactly the text you give it. Retype curly quotes as
' or ". Then check the file parses, without running it:
node --check app.js
The same escape trap in Python's own strings is behind the unicodeescape error.
How DMN learned it
It came up, and was fixed, in 2 of our own sessions. DMN kept the fix as one line:
When patching JS files via a Python heredoc, use raw strings (r"""...""") or the Edit tool, since plain
Python literals turn `\n` into real newlines and break JS strings.
DMN reads your agents' past sessions on your machine. When the same error is fixed the same way in two or more of them, it keeps the fix as a one-line lesson. When the error turns up again, Claude Code is told the fix straight away, and any agent can search what earlier sessions found. How DMN keeps what agents learn.