Typescript build getting errors from node_modules folder

三世轮回 提交于 2019-11-29 01:45:49
Baffled Monkey

I was struggling with this as well.

I added the following to the top of the TS file that contained the import {bootstrap} line:

///<reference path="../node_modules/angular2/typings/browser.d.ts"/> 

Your path may be different of course for that file.

Srikanth Injarapu

If you're targeting ES5, add "node_modules/typescript/lib/lib.es6.d.ts" to tsconfig.json file :

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "outDir": "built",
        "rootDir": ".",
        "sourceMap": false
    },
    "files": [
      "helloworld.ts",
      "node_modules/typescript/lib/lib.es6.d.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

While this solution

/// <reference path="../typings/browser.d.ts" />
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app/main';

bootstrap(AppComponent);

works well, wenn using gulpjs I prefer however instead of populating source file with comments, an addition of typings file directly to the source of the corresponding gulpjs task, like for example:

gulp.task('typescript', function () {
  return gulp
    .src([
      'typings/browser.d.ts',
      tsSrc + '**/*.ts'
    ])
    .pipe(sourcemaps.init())
    .pipe(typescript(tscConfig.compilerOptions))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(appSrc + 'js/'));
});

In RC1 demo, the shim is provided by the core-js module and type definitions are managed by the typings tool. Adding typings/index.d.ts to gulp.src should fix the issue:

function buildTypeScriptFn(files) {
  files = files || ['app/**/*.ts','typings/index.d.ts'];

  return function () {
    var tsResult = gulp.src(files)
      .pipe(changed(paths.dirs.build, { extension: '.js' }))
      .pipe(ts(tscConfig.compilerOptions));

    return merge(tsResult.dts, tsResult.js)
      .pipe(gulp.dest(paths.dirs.build));
  }
}

gulp.task('ts', buildTypeScriptFn());

i had the same problem, just try running not with "npm start", but with "npm run lite". Its much more convenient to use.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!