无法使用VS Code调试器将断点设置为typescript

时间:2017-07-06 18:06:40

标签: node.js debugging typescript visual-studio-code

我的项目具有以下结构

.vscode
|    |____launch.json
dist
|    |____server.js
|    |____server.js.map
node_modules
src
|    |____server.ts
gulpfile.js
package.json
tsconfig.json

我的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach",
            "type": "node",
            "request": "attach",
            "port": 9229,
            "address": "localhost",
            "restart": false,
            "sourceMaps": true,
            "outFiles": ["${workspaceRoot}/dist/**/*.js"],
            "localRoot": "${workspaceRoot}/src/**/*.js",
            "remoteRoot": null,
            "protocol": "inspector"
        }
    ]
}

我的gulpfile.js

const gulp = require('gulp');
const ts = require('gulp-typescript');
const nodemon = require('gulp-nodemon');
const sourcemaps = require('gulp-sourcemaps');
const JSON_FILES = ['src/*.json', 'src/**/*.json'];

// pull in the project TypeScript config
const tsProject = ts.createProject('tsconfig.json');

gulp.task('scripts', () => {
    return tsProject.src()
        .pipe(sourcemaps.init())
        .pipe(tsProject())
        .js.pipe(sourcemaps.write("."))
        .pipe(gulp.dest('dist'));
});

gulp.task('watch', ['scripts'], () => {
    return gulp.watch('src/**/*.ts', ['scripts']);
});

gulp.task('assets', function () {
    return gulp.src(JSON_FILES)
        .pipe(gulp.dest('dist'));
});

gulp.task('nodemon', ['scripts', 'assets', 'watch'], () => {
    nodemon({
        script: './dist/bin/start.js',
        nodeArgs: ['--inspect']
    });
});

gulp.task('default', ['nodemon']);

我的tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "outDir": "dist"
    },
    "include": [
        "src/**/*.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

我使用执行npm run startdev的{​​{1}}启动我的开发环境。因此,运行gulp的默认gulp任务,将我的代码编译到nodemon文件夹。我可以附加调试器,但每当我尝试设置断点时,它都会显示为灰色dist我认为我的Breakpoint ignored because generated code not found (source map problem?).配置不正确。我在这里缺少什么?

0 个答案:

没有答案