microsoft / microsoft/TypeScript

VS Code variable inspection / watch does not work for default imports in NodeJS environment

Open
#36,304 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: JS Emit
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.