Skip to content

node --watch won't restart after SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX] and the file is subsequently modified #61153

Description

@gitenstuff

Version

v24.11.1

Platform

linux

Subsystem

No response

What steps will reproduce the bug?

Run bash node --watch app.ts

  • 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

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    loadersIssues and PRs related to ES module loaders.strip-typesIssues and PRs related to TypeScript type stripping.watch-modeIssues and PRs related to watch mode.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions