Repository: vscode
Issue: Debugger fails with SyntaxError when using an external directory for TypeScript (outDir)
Labels: bug,search,confirmed,search-api

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
Commit: 379476f0e13988d90fab105c5c19e7abc8b1dea8
Date: 2021-08-04T23:13:12.822Z
Electron: 13.1.7
Chrome: 91.0.4472.124
Node.js: 14.16.0
V8: 9.1.269.36-electron.0
OS: Windows_NT x64 10.0.19042
TypeScript: 4.3.5

Steps to Reproduce:

1. Follow the TypeScript tutorial here: https://code.visualstudio.com/docs/typescript/typescript-tutorial
2. Then follow this one: https://code.visualstudio.com/docs/typescript/typescript-compiling
3. Then follow this one: https://code.visualstudio.com/docs/typescript/typescript-debugging
4. Debugging should now work as expected
5. Change tsconfig.json outDir to an absolute directory that is still within the workspace (e.g. `D:\\OneDrive\\Programming\\Personal\\TypeScript\\Sandbox\\out` where `D:\\OneDrive\\Programming\\Personal\\TypeScript\\Sandbox` is the workspace root)
6. Change launch.json outFiles to an absolute directory that matches that new output directory (e.g. `D:\\OneDrive\\Programming\\Personal\\TypeScript\\Sandbox\\out\\**\\*.js`)
7. Debugging should still work as expected
8. Now change outDir and outFiles to a totally different directory that is outside the workspace (e.g. D:\someNewDirectory)
9. Expect: Debugging still works as expected
10. Actual: `SyntaxError: Unexpected token ':'`

I appreciate I must be doing something dumb here. I'm new to TypeScript and Node and finding it difficult to narrow down where the issue is coming from (VS itself, some TypeScript setting, some node setting, etc.). I have tried various search engine attempts to narrow it down but have failed to find any obvious issues and it's hard for me to work out what VS Code is doing. I apologise in advance if this is a dumb issue, but a section in the tutorial about using an external directory would be super helpful at the very least to understand how it's working.

I have attached the project and commented the 2 directories where one works and the other does not (launch.json and tsconfig.json). Hopefully this is something trivial and this issue will at least help other people find the issue :). I installed TypeScript globally and additionally tried to use settings.json to tell VSCode to use my global version rather than the one installed with VSCode to see if that would make any difference (and tell VSCode to use that version by doing the version switching command) but I get the same issue.

Full error in debug console:
Debugger attached.
Waiting for the debugger to disconnect...
d:\OneDrive\Programming\Personal\TypeScript\Sandbox\src\sandbox.ts:1
let message: string = 'Hello Newwwwwwwer World';
           ^
SyntaxError: Unexpected token ':'
    at Object.compileFunction (node:vm:355:18)
    at wrapSafe (node:internal/modules/cjs/loader:1022:15)
    at Module._compile (node:internal/modules/cjs/loader:1056:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47


[Sandbox.zip](https://github.com/microsoft/vscode/files/6999975/Sandbox.zip)