启用S​​ourceMap的VSCODE DEBUG DEBUG打字错误错误

发布于 2025-01-31 17:31:02 字数 2630 浏览 1 评论 0原文

我有一个打字稿应用。 SRC在SRC目录中。如果我运行构建并启动应用程序,则可以正常工作。现在我想调试它。 https://code.vis.visalstudio.com/docs/docs/docs/docs/typescript-cript-tuterororage _debugging

打字稿是模块格式。将在磁盘目录中生成的输出没有模块,因为tsconfig.json文件具有选项集。

因此,问题是,如果我制作任务的配置。这是一个节点应用。

启动.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "name": "Launch Program",
      "skipFiles": ["<node_internals>/**"],
      "program": "${workspaceFolder}/src/index.ts",
      "preLaunchTask": "tsc: build - tsconfig.json",
      "console": "integratedTerminal",
      "outFiles": ["${workspaceFolder}/dist/**/*.js"]
    }
  ]
}

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "typescript",
      "tsconfig": "tsconfig.json",
      "problemMatcher": ["$tsc"]
    }
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "experimentalDecorators": true ,
    "emitDecoratorMetadata": true ,
    "module": "commonjs",
    "sourceMap": true ,
    "outDir": "./dist" ,
    "sourceRoot": "./src/",
    "esModuleInterop": true ,
    "forceConsistentCasingInFileNames": true ,
    "strict": true ,
    "skipLibCheck": true 
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

错误告诉我:(单击我单击VSCODE F5中的启动调试按钮后触发)

PS C:\Users\ruper\Documents\Code\javaScript\microtrading>  ${env:NODE_OPTIONS}='--require c:/Users/ruper/.vscode/extensions/ms-vscode.js-debug-nightly-2022.5.2017/src/bootloader.bundle.js --inspect-publish-uid=http'; ${env:VSCODE_INSPECTOR_OPTIONS}='{"inspectorIpc":"\\\\.\\pipe\\node-cdp.3248-1.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\ruper\\AppData\\Local\\Temp\\node-debug-callback-5c4d148c5f27f944"}'; & 'C:\Program Files\nodejs\node.exe' '.\src\index.ts' 
Debugger attached.
(node:22324) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Waiting for the debugger to disconnect...
C:\Users\ruper\Documents\Code\javaScript\microtrading\src\index.ts:1
import dotenv from 'dotenv'
^^^^^^

SyntaxError: Cannot use import statement outside a module

I have a typescript app. The src is in the src directory. If i run the build, and start the app, it works. Now I want to debug it. https://code.visualstudio.com/docs/typescript/typescript-tutorial#_debugging

The typescript is in module format. The output which will be generated in the disk directory has no module, because the tsconfig.json file has the option set.

So, the problem is, if I make the config of the tasks.json, launch.json and run debug, it won't work. It's a node app.

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "name": "Launch Program",
      "skipFiles": ["<node_internals>/**"],
      "program": "${workspaceFolder}/src/index.ts",
      "preLaunchTask": "tsc: build - tsconfig.json",
      "console": "integratedTerminal",
      "outFiles": ["${workspaceFolder}/dist/**/*.js"]
    }
  ]
}

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "typescript",
      "tsconfig": "tsconfig.json",
      "problemMatcher": ["$tsc"]
    }
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "experimentalDecorators": true ,
    "emitDecoratorMetadata": true ,
    "module": "commonjs",
    "sourceMap": true ,
    "outDir": "./dist" ,
    "sourceRoot": "./src/",
    "esModuleInterop": true ,
    "forceConsistentCasingInFileNames": true ,
    "strict": true ,
    "skipLibCheck": true 
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

The Error tells me: (Trigger after I click Start Debugging Button in VSCode F5)

PS C:\Users\ruper\Documents\Code\javaScript\microtrading>  ${env:NODE_OPTIONS}='--require c:/Users/ruper/.vscode/extensions/ms-vscode.js-debug-nightly-2022.5.2017/src/bootloader.bundle.js --inspect-publish-uid=http'; ${env:VSCODE_INSPECTOR_OPTIONS}='{"inspectorIpc":"\\\\.\\pipe\\node-cdp.3248-1.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\ruper\\AppData\\Local\\Temp\\node-debug-callback-5c4d148c5f27f944"}'; & 'C:\Program Files\nodejs\node.exe' '.\src\index.ts' 
Debugger attached.
(node:22324) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Waiting for the debugger to disconnect...
C:\Users\ruper\Documents\Code\javaScript\microtrading\src\index.ts:1
import dotenv from 'dotenv'
^^^^^^

SyntaxError: Cannot use import statement outside a module

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文