Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

typescript - VSCode debugging: Uncaught ReferenceError: require is not defined

I use VSCode to debug my ts-node TypeScript code. Sometimes this leads to problems that (I guess) stem from the fact that the code which is executed is JavaScript, but the code that I see is TypeScript:

For example, sometimes the variable foo gets renamed to _foo by the transpiler. Then, I cannot inspect the variable foo's content by hovering over it. Only in the debug window, I see that foo got renamed to _foo. I guess I have to live with that.

Far more severe are the problems with the Debug Console, which I often use for on-the-fly evaluation of expressions. I have a class MyClass that is used in the code I am currently debugging. The class is imported via a

import MyClass from './MyClass'

or similar. Now I want to use that class in the Debug Console window, while the debugger is paused (e.g. by a breakpoint). Because the class is already imported in the code that is currently debugged, I try it by just using it, like it is used in the current code:

MyClass
Uncaught ReferenceError: MyClass is not defined

No idea why it is not defined in the current context. So let's try to import it again. Since we are now in JavaScript, let's try require:

require("./MyClass")
Uncaught ReferenceError: require is not defined
  • How can it be that require is not defined?
  • How can I use this class in the Debug Window?

This is not just the Debug Console window, but also affects the Watch Expressions window and probably others.

question from:https://stackoverflow.com/questions/65842029/vscode-debugging-uncaught-referenceerror-require-is-not-defined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...