How to debug server side TypeScript code in WebStorm
将其与Visual Studio Code进行比较,您所要做的就是允许源映射,而VSCode将调试TypeScript,但是我无法在WebStorm上实现相同功能。
我可以轻松调试WebStorm中的服务器端JavaScript,但不能调试TypeScript
对于其他在WebStorm / IDEA中尝试调试TypeScript的人来说,我与OP有类似的挫败感(可能出于不同的原因)。我的问题很简单,我没有在节点运行配置中将工作目录设置为
更多信息...
中的.ts源文件
typescript版本:2.0.3
文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | { "compilerOptions": { "jsx":"react", "module":"commonjs", "noImplicitAny": false, "outDir":"dist", "preserveConstEnums": true, "removeComments": true, "sourceMap": true, "target":"es6", "moduleResolution":"node" }, "exclude": [ "node_modules", "dist" ] } |
笑话配置(在
1 2 3 4 5 6 7 8 9 | "jest": { "scriptPreprocessor":"<rootDir>/node_modules/ts-jest/dist/preprocessor.js", "testRegex":"(/__tests__/.*|\\\\.(test|spec))\\\\.(ts|tsx)$", "moduleFileExtensions": [ "ts", "tsx", "js" ] } |
运行配置...
工作目录:
JavaScript文件:
应用程序参数:
希望有帮助!
我正在使用称为
首先添加您的
1 2 3 4 | "devDependencies": { "ts-node":"8.1.0", "typescript":"3.2.4" }, |
运行
显然,这些版本会移动。您可能会在
然后您可以添加断点。我看到的唯一缺点是您必须在配置中定义Javascript文件(这是一个ts文件),而不是右键单击运行。
如果出现
对于围绕typescript源运行WebStorm(2017.2.3)调试器,我做了:
-
工作目录:
root/of/the/project (位于我的package.json 所在的位置) -
JavaScript文件:
dist/index.js
我正在用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | const gulp = require('gulp'); const ts = require('gulp-typescript'); const sourcemaps = require('gulp-sourcemaps'); const merge = require('merge2'); const tsProject = ts.createProject('tsconfig.json', { declaration: true, typescript: require('typescript'), }); gulp.task('default', () => { const result = gulp.src('./app/**/*.ts') .pipe(sourcemaps.init()) .pipe(sourcemaps.identityMap()) // optional .pipe(tsProject()); return merge([ result.js .pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '../app' })) .pipe(gulp.dest('dist')), result.dts .pipe(gulp.dest('dist')), ]); }); |
位于'./app'文件夹中的所有源TS文件,位于
通过
感谢@Ekaterina,我能够使用Typescript运行Node debug。