Microsoft/TypeScript

`tsc --build --watch` produces stray `.js`/`.js.map` files when adding a file to upstream project

Open

#61,717 opened on May 17, 2025

View on GitHub
 (1 comment) (0 reactions) (0 assignees)TypeScript (48,455 stars) (6,726 forks)batch import
BugDomain: tsc -bHelp Wanted

Description

🔎 Search Terms

tsc build watch extra unwanted stray .js .js.map files projects

🕗 Version & Regression Information

  • This changed between versions 5.5 and 5.6

⏯ Playground Link

No response

💻 Code

Repo with the repro: https://github.com/echentw/tsc-watch-bug-repro

  • Instructions for repro-ing are under "Bug 1 repro instructions".

Description of the repro:

  • The setup:
    • The repo contains 2 TS projects: project1 and project2
    • The .js and .js.map files should be outputted to project1/dist/ and project2/dist/
    • project1 defines some math functions that project2 imports and uses
    • The git branches:
      • the main branch has the base code
      • the multiply-function branch has one additional commit on top of main, which:
        • adds a project1/src/multiply.ts file which exports a multiply function
        • and edits project2/src/main.ts to import and use that multiply function.
  • When you switch from main to the multiply-function branch while tsc --build --watch is running from within project2/, then the following unwanted files are created:
    • project1/src/multiply.js
    • project1/src/multiply.js.map

I checked that this doesn't happen with TS version 5.5, but it does happen with TS version 5.6 and onwards.

🙁 Actual behavior

project1/src/multiply.js and project1/src/multiply.js.map are created

🙂 Expected behavior

project1/src/multiply.js and project1/src/multiply.js.map should not be created

Additional information about the issue

Ideally, switching branches or modifying code while tsc --build --watch is running wouldn't produce stray .js/.js.map files. They are unpleasant to deal with and can be accidentally committed.

No response

Contributor guide