Gulp中的TypeScript编译器说它找不到@angular模块但编译得很好

Jui*_*icy 15 typescript gulp angular

当我的gulp任务编译我的打字稿时,我遇到了很多"错误"的错误.这是相关的gulp task:

var tsProject = typescript.createProject('tsconfig.json', {noResolve: true});

gulp.task('build-ts', function() {
    gulp.src(appDev + '**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(typescript(tsProject))
        .pipe(sourcemaps.write())
        //.pipe(jsuglify())
        .pipe(gulp.dest(appProd));
    gulp.src(appDev + '**/*.+(html|css)')
        .pipe(gulp.dest(appProd));
});
Run Code Online (Sandbox Code Playgroud)

这些是我得到的错误:

[09:38:52] Starting 'default'...
[09:38:52] Finished 'default' after 8.88 ms
ng/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
ng/app.component.ts(5,12): error TS2304: Cannot find name 'module'.
ng/app.module.ts(1,26): error TS2307: Cannot find module '@angular/core'.
ng/app.module.ts(2,31): error TS2307: Cannot find module '@angular/platform-browser'.
ng/app.module.ts(3,31): error TS2307: Cannot find module '@angular/common'.
[...]
[09:38:53] TypeScript: 27 semantic errors
[09:38:53] TypeScript: emit succeeded (with errors)
[BS] Proxying: http://0.0.0.0:5000
Run Code Online (Sandbox Code Playgroud)

我的树结构看起来像这样(简化):

.
??? gulpfile.js
??? ng
??? node_modules
??? package.json
??? tsconfig.json
??? typings.json
??? web
Run Code Online (Sandbox Code Playgroud)

Typescript编译器无法找到的所有模块实际上都在node_modules,我的最终应用程序工作正常,尽管存在所有错误.

这是我的tsconfig.js:

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "./app"
  },
  "filesGlob": [
    "./app/**/*.ts",
    "!./node_modules/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ],
  "atom": {
    "rewriteTsconfig": true
  }
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能摆脱这些"误报"错误.

tib*_*bus 8

gulp.js文件中的行

var tsProject = typescript.createProject('tsconfig.json', {noExternalResolve: true, noResolve: true});
Run Code Online (Sandbox Code Playgroud)

应该

var tsProject = typescript.createProject('tsconfig.json');
Run Code Online (Sandbox Code Playgroud)

因为我们想加载外部输入.

而且你还需要在top.ts文件中加载顶部:

/// <reference path="../typings/index.d.ts" />
Run Code Online (Sandbox Code Playgroud)

我确实克隆了你的项目,并在此之后编译而没有警告.