You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
node --watch won't restart after SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX] and the file is subsequently modified #61153
edit app.ts => if you make a change without causing a syntax error, e.g., edit a string, copy/delete lines, then --watch works as expected.
however it the edit causes SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]: then app.ts will not be restarted, no matter how the file is subsequently modified, e.g., fixed the syntax error.
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
Node should restart every time the file is changed
What do you see instead?
Run node --watch app.ts
Completed running 'app.ts'. Waiting for file changes before restarting...
Now start editing. If the file you are editing gets saved (auto save 5 seconds on this machine) while you are in the middle of typing a line then output is the Syntax Error exception as expected.
Restarting 'app.ts'
node:internal/modules/run_main:107
triggerUncaughtException(
^
file:///home/user/dev/rfc/app.ts:38
throw new Error(`"${this.cmd}" not found on system path`
}
^
}
SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]: Expected ',', got '}'
at parseTypeScript (node:internal/modules/typescript:72:36)
at processTypeScriptCode (node:internal/modules/typescript:146:42)
at stripTypeScriptModuleTypes (node:internal/modules/typescript:209:22)
at ModuleLoader.<anonymous> (node:internal/modules/esm/translators:660:29)
at #translate (node:internal/modules/esm/loader:541:20)
at afterLoad (node:internal/modules/esm/loader:594:29)
at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:599:12)
at #createModuleJob (node:internal/modules/esm/loader:623:36)
at #getJobFromResolveResult (node:internal/modules/esm/loader:329:34)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:294:41) {
code: 'ERR_INVALID_TYPESCRIPT_SYNTAX'
}
Node.js v24.11.1
Failed running 'app.ts'. Waiting for file changes before restarting...
Meanwhile you finish typing your line and now all of the syntax is peachy clean within a few more seconds.
app.ts is never restarted no matter what changes are made to it
Neither manual save nor auto-save will trigger a restart.
Mediation is ctrl-c, followed by node --watch app.ts
@marco-ippolito
I'm not surprised to hear it's not reproducing. Otherwise there would be a ton of issues ...
I did additional testing: --watch works as expected when app crashes on any other unhandled exception. It only stops working when node crashes with a syntax error...
bar
Completed running '/tmp/watch.ts'. Waiting for file changes before restarting...
Restarting '/tmp/watch.ts'
/tmp/watch.ts:3
struct {};
^
SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]: Expected ';', '}' or <eof>
at parseTypeScript (node:internal/modules/typescript:72:36)
at processTypeScriptCode (node:internal/modules/typescript:146:42)
at stripTypeScriptModuleTypes (node:internal/modules/typescript:209:22)
at Module._compile (node:internal/modules/cjs/loader:1713:15)
at Object..js (node:internal/modules/cjs/loader:1893:10)
at Module.load (node:internal/modules/cjs/loader:1481:32)
at Module._load (node:internal/modules/cjs/loader:1300:12)
at TracingChannel.traceSync (node:diagnostics_channel:328:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:245:24)
at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) {
code: 'ERR_INVALID_TYPESCRIPT_SYNTAX'
}
Node.js v24.11.1
Failed running '/tmp/watch.ts'. Waiting for file changes before restarting...
Restarting '/tmp/watch.ts'
bar
Completed running '/tmp/watch.ts'. Waiting for file changes before restarting...
OH! I can only replicate when "type": "module" is set in package.json, that's probably a big clue. Replicator @gitenstuff and non-replicators @marco-ippolito and @Xstoudi, can you try out switching to type-module and see if that makes a difference in either direction?
I am still able to replicate with node v24.12.0 exactly as shown in the video above. (As shown in the video, that was using v24.7.0). And I found this issue because a colleague using Windows encountered the same issue.
Happens because watch:import event is never emitted as this.loadAndTranslate throws a syntax error before. I opened a PR to fix it, hope it's the way to fix it.
Activity
marco-ippolito commentedon Dec 23, 2025
I cannot reproduce on macos
gitenstuff commentedon Dec 23, 2025
@marco-ippolito
I'm not surprised to hear it's not reproducing. Otherwise there would be a ton of issues ...
I did additional testing: --watch works as expected when app crashes on any other unhandled exception. It only stops working when node crashes with a syntax error...
Xstoudi commentedon Dec 23, 2025
I cannot reproduce on Linux Mint either.
gitenstuff commentedon Dec 23, 2025
Can you please give me some guidelines regarding desktop capture video which can be posted or linked to here so y'all don't think i'ma crazy?
juanarbol commentedon Dec 27, 2025
can't repro in Linux
juanarbol commentedon Dec 27, 2025
The easiest for all of us to look at the better. Use anything that works for you and us.
robsimmons commentedon Dec 29, 2025
Here's me replicating (OSX 15.6.1 (24G90), Node.js v24.7.0)
Screen.Recording.2025-12-29.at.3.52.11.PM.mov
robsimmons commentedon Dec 29, 2025
OH! I can only replicate when
"type": "module"is set in package.json, that's probably a big clue. Replicator @gitenstuff and non-replicators @marco-ippolito and @Xstoudi, can you try out switching to type-module and see if that makes a difference in either direction?gitenstuff commentedon Dec 30, 2025
@robsimmons
Weird, now I can't replicate with
"type"="commonjs"nor"type"="module"robsimmons commentedon Dec 30, 2025
I am still able to replicate with node v24.12.0 exactly as shown in the video above. (As shown in the video, that was using v24.7.0). And I found this issue because a colleague using Windows encountered the same issue.
Xstoudi commentedon Dec 30, 2025
Yep, can now reproduce, but only when
typeismodule.2 remaining items
Xstoudi commentedon Dec 31, 2025
I git bisected it to 2fafe4c
Xstoudi commentedon Jan 1, 2026
Happens because
watch:importevent is never emitted asthis.loadAndTranslatethrows a syntax error before. I opened a PR to fix it, hope it's the way to fix it.robsimmons commentedon Jan 2, 2026
@Xstoudi I really appreciate you doing the digging to fix this!
esm: ensure watch mode restarts after syntax errors
esm: ensure watch mode restarts after syntax errors
esm: ensure watch mode restarts after syntax errors