Alex Long
Alex Long

Reputation: 281

Why does VSCode debugger always show node imports as undefined?

The VSCode debugger always shows imports as undefined even when they're clearly not, why does it do this and is there a way I can fix it?

In below example, the variable "Lot" is imported and is not undefined as is demonstrated by the result of the console.log line, however when I manually type in "Lot" in the debugger it says it's undefined.

Screenshot with debugger and code

Code from example:

import Lot from '../db/models/Lot'

console.log(Lot === undefined) // prints false
console.log("break") // Debugger stopped at this breakpoint shows Lot as undefined 

If I assign Lot to a local variable then it works:

const Lot2 = Lot
console.log("break") // Debugger stopped at this breakpoint shows Lot2 as defined

Upvotes: 5

Views: 1432

Answers (1)

James
James

Reputation: 108

I found out something about this: in the Closure section of the debugger window, you should find your imported module has _1 after its name, then you would access it with Lot_1.Lot.

This post suggests that this happens when the compilerOptions is below ES6

Upvotes: 6

Related Questions