2017-05-16 6 views
0

Kürzlich wechselte ich zu Gulp. Nach einigem Hin und Her gelang es mir endlich, mein Projekt zu kompilieren. Jetzt kann ich es nicht starten, VS Code sagt mir das:TypScript-Projekt kann nicht gestartet werden

Kann Programm '../src/bootstrap.ts' nicht starten; Das Festlegen des Attributs 'outFiles' könnte hilfreich sein.

Wenn ich TSC zum Kompilieren und Ausführen der App verwenden, funktioniert alles einwandfrei.

Hier sind meine Config-Dateien:

launch.json:

{ 
    "version": "0.2.0", 
    "configurations": [ 
     { 
      "type": "node", 
      "request": "launch", 
      "name": "Launch Program", 
      "preLaunchTask": "build", 
      "sourceMaps": true, 
      "program": "${workspaceRoot}/src/bootstrap.ts", 
      "outFiles": ["${workspaceRoot}/lib/**/*.js"], 
      "cwd": "${workspaceRoot}" 
     } 
    ] 
} 

tasks.json:

{ 
    "version": "0.1.0", 
    "command": "gulp", 
    "isShellCommand": true, 
    "args": [ 
     "--no-color" 
    ], 
    "tasks": [ 
     { 
      "taskName": "build", 
      "isBuildCommand": true, 
      "showOutput": "always", 
      "problemMatcher": "$tsc" 
     } 
    ] 
} 

gulpfile.js:

var gulp = require('gulp') 
var ts = require('gulp-typescript'); 
var sourcemaps = require('gulp-sourcemaps'); 

gulp.task('copy', function() { 
    var copyResult = gulp.src('src/templates/*.hbs') 
     .pipe(gulp.dest('lib/templates/')); 

    return copyResult; 
}); 

gulp.task('compile', function() { 
    var tsResult = gulp.src('src/**/*.ts') 
     .pipe(sourcemaps.init()) 
     .pipe(ts({ 
      module: "commonjs", 
      target: "es6", 
      noImplicitAny: false, 
      typeRoots: ["node_modules/@types"], 
      declaration: true, 
      experimentalDecorators: true, 
      emitDecoratorMetadata: true 
     })); 

    return tsResult.js 
     .pipe(sourcemaps.write('.', { sourceRoot: function (file) { return file.cwd + '/lib'; } })) 
     .pipe(gulp.dest('lib')); 
}); 

gulp.task('build', ['copy', 'compile']); 

Und hier ist die Projektordner-Struktur:

- lib (compiled output) 
    - api 
    - engine 

- src 
    - api 
    - engine 
    - bootstrap.ts 

- gulpfile.js 
- tsconfig.json 

So kann ich nicht finden, was mit dem Outfiles Einstellung falsch ist.

BEARBEITEN Ok, ich denke, ich habe gefunden, was vor sich geht.

Dies ist die Datei, die von js.map TSC (Zuordnungsattribut weggelassen) erzeugt:

{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[]} 

Und dies ist die Datei js.map dass gulp (Mapping- und sourceContent weggelassen) erzeugt:

{"version":3,"sources":["bootstrap.ts"],"names":[]} 

Der Unterschied ist die offensichtliche Abwesenheit von relativen Ordnerpfad in der Quellen Eigenschaft. Wenn ich also mit gulp kompiliere, kann VSCode die .ts-Dateien nicht finden. Also ich denke, ich muss einen Weg finden, alle Dateien zu kompilieren, genau wie TSC mit Schluck.

Antwort

0

Ok, hab es!

Den folgenden Code hinzufügen, bevor sourcemaps.write() das Problem behebt.

.pipe(sourcemaps.mapSources(function (sourcePath, file) { 
    // source paths are prefixed with '../src/' 
    return '../src/' + sourcePath; 
})) 
Verwandte Themen