如何在WebStorm中调试服务器端TypeScript代码 [英] How to debug server side TypeScript code in WebStorm

查看:628
本文介绍了如何在WebStorm中调试服务器端TypeScript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将其与Visual Studio Code进行比较,您所要做的就是允许源映射,而VSCode将调试TypeScript,但是我无法在WebStorm上实现相同的功能。

Comparing this to Visual Studio Code all you need to do is allow source maps and VSCode will debug TypeScript however I can't achieve the same on WebStorm.

I可以轻松调试WebStorm中的服务器端JavaScript,但不能调试TypeScript

I can easily debug server side JavaScript in WebStorm but not TypeScript

推荐答案

对于在WebStorm / IDEA中调试TypeScript的其他人,我不得不与OP类似的挫败感(可能出于不同的原因)。我的问题仅仅是因为我没有在节点运行配置中将工作目录设置为 dist 文件夹。我正在Jest中运行测试,并假定工作目录应该是我项目的根目录。将其设置为 dist 并开始调试!

For anyone else wrestling with debugging TypeScript in WebStorm/IDEA, I had similar frustrations as OP (possibly for different reason). My issue was simply that I didn't set the working directory to the dist folder in the node run configuration. I am running tests in Jest and assumed the working dir should be the root of my project. Set it to dist and debugging started working!

更多信息...

src

打字稿版本:2.0.3

Typescript version: 2.0.3

文件 tsconfig.json

{
  "compilerOptions": {
    "jsx": "react",
    "module": "commonjs",
    "noImplicitAny": false,
    "outDir": "dist",
    "preserveConstEnums": true,
    "removeComments": true,
    "sourceMap": true,
    "target": "es6",
    "moduleResolution": "node"
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Jest配置(在 package.json ):

Jest config (in package.json):

  "jest": {
    "scriptPreprocessor": "<rootDir>/node_modules/ts-jest/dist/preprocessor.js",
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ]
  }

运行配置...

工作目录:< project_root> / dist

JavaScript文件: ../ node_modules / jest-cli / bin / jest.js

Javascript file: ../node_modules/jest-cli/bin/jest.js

应用程序参数:-runInBand

希望有帮助!

这篇关于如何在WebStorm中调试服务器端TypeScript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆