【问题标题】:gulp-tsc src folder not found找不到 gulp-tsc src 文件夹
【发布时间】:2017-03-04 11:03:26
【问题描述】:

我正在尝试使用 Angular2 创建和 .net 核心应用程序。 我不断收到以下错误

/wwwroot/NodeLib/gulp-tsc/src/compiler.ts' not found.

我不知道我错过了什么。

tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "outDir": "../wwwroot/app",
    "types": []
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

package.json

{
  "name": "angular2withvs2015",
  "version": "1.0.0",
  "dependencies": {
    "@angular/common": "~2.1.1",
    "@angular/compiler": "~2.1.1",
    "@angular/core": "~2.1.1",
    "@angular/forms": "~2.1.1",
    "@angular/http": "~2.1.1",
    "@angular/platform-browser": "~2.1.1",
    "@angular/platform-browser-dynamic": "~2.1.1",
    "@angular/router": "~3.1.1",
    "@angular/upgrade": "~2.1.1",
    "bootstrap": "3.3.7",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {
    "gulp": "3.9.1",
    "rimraf": "^2.5.4",
    "gulp-typescript": "^3.1.2",
    "typescript": "^2.0.7",
    "gulp-tsc": "^1.2.5",
    "@types/node": "6.0.40"
  }
}

Gulp.js

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

var gulp = require('gulp'),
 rimraf = require('rimraf');

gulp.task('clean', function (cb) {
    return rimraf('./wwwroot/NodeLib/', cb)
});

gulp.task('copy:lib', function () {
    return gulp.src('node_modules/**/*')
        .pipe(gulp.dest('./wwwroot/NodeLib/'));
});

gulp.task('copy:systemjs', function () {
    return gulp.src('Scripts/systemjs.config.js')
        .pipe(gulp.dest('./wwwroot/'));
});
var tsProject = ts.createProject('Scripts/tsconfig.json', {
    typescript: require('typescript')
});
gulp.task('ts', function () {
    var tsResult = gulp.src("Scripts/**/*.ts") // instead of gulp.src(...)
        .pipe(tsProject());

    return tsResult.js.pipe(gulp.dest('./wwwroot'));
});


gulp.task('watch', ['watch.ts']);
gulp.task('watch.ts', ['ts'], function () {
    return gulp.watch('Scripts/**/*.ts', ['ts']);
});

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

【问题讨论】:

    标签: angular typescript gulp


    【解决方案1】:

    问题是由 \node_modules\gulp-tsc\tsconfig.json 引起的

    "files": [
        "src/compiler.ts",
        "src/shellescape.ts",
        "src/tsc.ts"
      ]
    

    当你执行 gulp 任务 copy:lib 时,node_modules 的内容被复制到 /wwwroot/NodeLib/

    据我了解,不需要全部内容。就我而言,我只想要 @angular 中的内容。所以,我创建了一个新的 gulp 任务,

    gulp.task('copy:lib@angular', function () {
        return gulp.src('node_modules/@angular/**/*')
            .pipe(gulp.dest('./wwwroot/NodeLib/@angular/'));
    });
    

    然后我删除了 wwwroot 中的 NodeLib 文件夹并执行了 copy:lib@angular gulp 任务。它创建了新的 NodeLib 文件夹,其中只有 @angular 文件夹。这解决了 Visual Studio 编译错误问题。

    【讨论】:

    • 谢谢让我看看
    【解决方案2】:

    gulp-tsc 从 1.2.* 到 1.3.* 似乎效果不佳。* 不确定主要贡献者在那里尝试做什么,但 1.3.2 尚不适用于 VS2015。恕我直言,您有两个选择:

    1. 使用 git 中的 gulp-tsc 并将引用的 src 目录复制到 NodeLib/ 或从那里删除 tsconfig.jason。无论哪种情况,您肯定会因为干净的 VS 构建而破坏其他依赖项。

    2. 1234563

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      • 2015-07-21
      • 1970-01-01
      • 2016-06-14
      • 2018-03-06
      • 1970-01-01
      • 2019-10-21
      相关资源
      最近更新 更多