gulp-typescript icon indicating copy to clipboard operation
gulp-typescript copied to clipboard

composite makes gulp fail but not tsc

Open FrancescElies opened this issue 2 years ago • 1 comments

Expected behavior:

gulp and tsc behaves the same, but I suspect I might be missing or missusing something.

NOTE: as soon as "composite": true is removed from tsconfig, gulp doesn't complain any more.

Actual behavior:

While tsc runs fine, gulp fails with the following.

npx gulp
C:\s\mytest\m_node_lib> npx gulp
[10:30:12] Using gulpfile C:\s\mytest\m_node_lib\gulpfile.js
[10:30:12] Starting 'default'...
[10:30:13] input src\index.ts
[10:30:13] input 1 item
[10:30:15] 'default' errored after 2.94 s
[10:30:15] TypeError: Cannot read property 'length' of undefined
    at Object.writeFile (C:\s\mytest\m_node_lib\node_modules\gulp-typescript\release\compiler.js:81:33)
    at writeFile (C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:16515:10)
    at emitBuildInfo (C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:109458:7)
    at emitSourceFileOrBundle (C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:109419:7)
    at forEachEmittedFile (C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:109176:18)
    at emitFiles (C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:109387:5)
    at emitWorker (C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:116758:26)
    at C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:116743:53
    at runWithCancellationToken (C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:116832:16)
    at Object.emit (C:\s\mytest\m_node_lib\node_modules\typescript\lib\typescript.js:116743:22)

Code:

gulpfile.js
var gulp = require("gulp");
var ts = require("gulp-typescript");
var debug = require("gulp-debug");

var tsProject = ts.createProject("tsconfig.json");

gulp.task("default", () => {
  return tsProject
    .src()
    .pipe(debug({ title: "input" }))
    .pipe(tsProject())
    .js.pipe(debug({ title: "js" }))
    .pipe(gulp.dest("dist"));
});
package.json
{
  "name": "mytest",
  "version": "1.0.0",
  "main": "dist/index.js",
  "devDependencies": {
    "gulp": "^4.0.2",
    "gulp-debug": "^4.0.0",
    "gulp-typescript": "^5.0.1",
    "typescript": "^5.0.4"
  }
}
src\index.ts
const a = 1;
tsconfig.json
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "outDir": "./dist",
    "declaration": true,
    "declarationMap": true,
    // As soon as you remove composite gulp works fine
    "composite": true  
  },
  "include": ["src/**/*"]
}

Am I doing something wrong?

FrancescElies avatar May 03 '23 08:05 FrancescElies

Upgrading gulp-typescript to "^6.0.0-alpha.1" seems to solve the problem.

diff --git a/package.json b/package.json
index 5116346..9563e36 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
   "devDependencies": {
     "gulp": "^4.0.2",
     "gulp-debug": "^4.0.0",
-    "gulp-typescript": "^5.0.1",
+    "gulp-typescript": "^6.0.0-alpha.1",
     "typescript": "^5.0.4"
   }
 }
diff --git a/tsconfig.json b/tsconfig.json
index 8238da7..05234da 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -4,8 +4,8 @@
   "compilerOptions": {
     "outDir": "./dist",
     "declaration": true,
-    "declarationMap": true
-    // "composite": true
+    "declarationMap": true,
+    "composite": true
   },
   "include": ["src/**/*"]
 }

I'll leave the issue open to wait for suggestions but feel free to close it.

FrancescElies avatar May 03 '23 09:05 FrancescElies