microsoft / microsoft/TypeScript
VS Code variable inspection / watch does not work for default imports in NodeJS environment
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.7.5
VSCode Version: 1.41.1 2019-12-18
Search Terms:
VSCode TypeScript Default Import Renamed Can't Debug Watch Inspect
Code
filea.ts
const a: string = "hello";
export default a;
fileb.ts
import a from "./filea"
console.log(a);
tsconfig.json
{
"compilerOptions": {
"lib": [ "es6" ],
"moduleResolution": "node",
"module": "commonjs",
"target": "es6",
"sourceMap": true
}
}
Expected behavior:
Works correctly in runtime
Variable a (imported one) can be inspected
Actual behavior:
Works correctly in runtime
Variable a (imported one) can't be inspected neither watched as VS Code says: not available
The problem is the variable a does not exist at runtime as the import is transpiled as:
const filea_1 = require("./filea");
console.log(filea_1.default);
Watching of filea_1.default works correctly, of course.
I am not sure if there is additional mapping somewhere, but everything else works well (breakpoints, other variable inspections...)
maybe the default imports can be transpiled as
const a = require("./filea").default;
console.log(a);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with filea.ts, fileb.ts, and tsconfig.json, then inspect the emitted CommonJS JavaScript and its source map while reproducing the watch behavior in VS Code. Determine whether default-import names can be mapped to the generated filea_1.default access without breaking existing runtime output. Done means the imported variable a can be inspected and watched in the NodeJS environment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100