gulp-typescript: tsProject.src() throws errors (gulp.src() doesn't) when using tsconfig.json without "exclude node_modules" section
Expected behavior:
I expected tsProject.src()
and gulp.src()
to compile .ts files without throwing a bunch of syntax errors from node_modules
when using tsconfig.json
without adding “exclude node_modules” section in tsconfig.json
.
Actual behavior:
tsProject.src()
throws a bunch of syntax errors from node_modules
(i.e., .d.ts error TS1005: ‘=’ expected, ‘;’ expected). However, gulp.src()
works fine. The only way to get tsProject.src()
to work is to add “exclude node_modules” section to tsconfig.json
. I can leave it out when using gulp.src()
. Why is that?
Your gulpfile:
var tsProject = ts.createProject('tsconfig.json');
gulp.task('script', function () {
var tsResult = tsProject // tsProject throws errors, but gulp doesn't
.src(['wwwroot/app/**/*.ts', 'typings/index.d.ts'])
.pipe(ts(tsProject));
return tsResult
.js
.pipe(gulp.dest('release'));
});
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
Note: I have to add the following in
tsconfig.json
when usingtsProject.src()
, but I can leave it out when usinggulp.src()
,
"exclude": [
"node_modules"
]
Question
- Why does
tsProject.src()
throw errors (whilegulp.src()
doesn’t) when “exclude” isn’t added totsconfig.json
? - What is the difference between using
tsProject.src()
andgulp.src()
fortsconfig.json
? - Why does the Using tsconfig.json section suggest using tsProject.src() instead of gulp.src()?
gulp.task('scripts', function() {
var tsResult = tsProject.src() // instead of gulp.src(...)
.pipe(ts(tsProject));
return tsResult.js.pipe(gulp.dest('release'));
});
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (7 by maintainers)
Then you’re probably using an older version (
2.*
). In version 2, you needed to writets(tsProject)
, which has been replaced bytsProject()
in version 3.Oh, that’s a different problem. You’re passing a stream of files (namely
tsProject()
) to gulp-typescript when you writets(tsProject())
. Thets
function expects an object with compiler options, not a stream. You should use.pipe(tsProject())
instead of.pipe(ts(tsProject()))
.