Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'length' of undefined on 3.1.6 #499

Closed
amiramw opened this issue Mar 19, 2017 · 9 comments
Closed

Cannot read property 'length' of undefined on 3.1.6 #499

amiramw opened this issue Mar 19, 2017 · 9 comments
Labels

Comments

@amiramw
Copy link

amiramw commented Mar 19, 2017

When running gulp default I get an exception when using gulp-typescript 3.1.6:

TypeError: Cannot read property 'length' of undefined
    at Object.writeFile (C:\Users\i066470\repos\storyboard\node_modules\gulp-typescript\release\compiler.js:64:32)
    at Object.writeFile (C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:8619:14)
    at printFile (C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:56633:20)
    at emitFile (C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:56590:21)
    at onSingleFileEmit (C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:8526:13)
    at Object.forEachTransformedEmitFile (C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:8503:21)
    at Object.emitFiles (C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:56573:12)
    at emitWorker (C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:59447:33)
    at C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:59410:66
    at runWithCancellationToken (C:\Users\i066470\repos\storyboard\node_modules\typescript\lib\typescript.js:59492:24)

Everything works fine when changing gulp-typescript to version 3.1.5.

Gulp file:

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

var tsProject = ts.createProject("tsconfig.json");
var SRC_GLOB = 'src/**/*';
var TEST_GLOB = 'tests/**/*';
var DEFS_GLOB = 'defs/**/*';

gulp.task("compile", function () {
	return tsProject.src().pipe(sourcemaps.init())
		.pipe(tsProject()).once("error", function () {
			this.once("finish", function () {
				process.exit(1);
			});
		})
		.js
		.pipe(sourcemaps.write())
		.pipe(gulp.dest("compiled"));
});

gulp.task("compile-no-fail", function () {
	return tsProject.src().pipe(sourcemaps.init())
		.pipe(tsProject())
		.js
		.pipe(sourcemaps.write())
		.pipe(gulp.dest("compiled"));
});

gulp.task("copy", function () {
	gulp.src(SRC_GLOB).pipe(gulp.dest("compiled/src"));
	gulp.src(TEST_GLOB).pipe(gulp.dest("compiled/tests"));
});

gulp.task('watch', function() {
	gulp.watch([SRC_GLOB, TEST_GLOB, DEFS_GLOB], ['watch-compilation']);
});

gulp.task('watch-compilation', ['compile-no-fail', 'copy']);

gulp.task('default', ['compile', 'copy']);

tsconfig.json:

{
	"compilerOptions": {
		"baseUrl": "",
		"paths": {
			"sap/watt/platform/plugin/platform/service/ui/AbstractPart": [
				"defs/watt/AbstractPart"
			],
			"sap.watt.common.perspective/command/PerspectiveSwitcher": [
				"defs/watt/PerspectiveSwitcher"
			],
			"sap/watt/core/I18nBundle": [
				"defs/watt/I18nBundle"
			],
			"sap.watt.saptoolsets.fiori.common.storyboard/*": [
				"src/storyboard_core/*"
			],
			"STF": [
				"defs/watt/STF"
			],
			"sinon": [
				"defs/watt/sinon"
			]
		},
		"noEmitOnError": true,
		"module": "amd",
		"target": "es5",
		"sourceMap": true,
		"declaration": false,
		"traceResolution": true,
		"outDir": "compiled",
		"alwaysStrict": true,
		"forceConsistentCasingInFileNames": true,
		"noImplicitReturns": true,
		"noImplicitThis": true,
		"allowJs": true
	},
	"include": [
		"src/**/*",
		"defs/**/*",
		"tests/**/*"
	],
	"exclude": [
		"node_modules"
	]
}
@ivogabe ivogabe added the Bug label Mar 19, 2017
@ivogabe
Copy link
Owner

ivogabe commented Mar 19, 2017

Which version of TypeScript are you using?

@amiramw
Copy link
Author

amiramw commented Mar 19, 2017

2.1.1

@ivogabe
Copy link
Owner

ivogabe commented Mar 19, 2017

@vladima Any idea why the sourceFiles argument of WriteFileCallback can be undefined? I see that it's marked optional in its definition:

export interface WriteFileCallback {
    (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void, sourceFiles?: SourceFile[]): void;
}

Is there some way to force it being set?

@SET001
Copy link

SET001 commented May 9, 2017

same problem here
tsc Version 2.3.0-dev.20170401
gulp-typescript 3.1.6

@SET001
Copy link

SET001 commented May 9, 2017

Solved after I reinstalled typesript package

@ivogabe
Copy link
Owner

ivogabe commented Jul 14, 2017

Is this still an issue to someone?

@amiramw
Copy link
Author

amiramw commented Jul 18, 2017

Seems solved with typescript 2.1.5

@amiramw amiramw closed this as completed Aug 18, 2017
@judemanutd
Copy link

judemanutd commented Sep 2, 2019

@ivogabe Got the same error

Current config

typescript : 3.6.2
gulp : 4.0.2
gulp-typescript : 5.0.1

var gulp = require("gulp");
var del = require("del");
var ts = require("gulp-typescript");
var tsProject = ts.createProject("tsconfig.json", {
  typescript: require("typescript"),
});

gulp.task("clean_tmp", function() {
  return del("tmp/**", { force: true });
});

gulp.task("build", function() {
  return tsProject
    .src()
    .pipe(tsProject())
    .js.pipe(gulp.dest("tmp"));
});

gulp.task("clean_dist", function() {
  return del("dist/**", { force: true });
});

gulp.task("move_dist", function() {
  return gulp.src("tmp/**").pipe(gulp.dest("dist"));
});

gulp.task("assets_copy", function() {
  return gulp
    .src([
      "src/ofm-auto.testing.json",
      "src/serviceAccountKey.json",
      "src/firebase-service-account.json",
    ])
    .pipe(gulp.dest("dist"));
});

gulp.task("views_copy", function() {
  return gulp.src(["src/views/**/*"]).pipe(gulp.dest("dist/views"));
});

gulp.task(
  "default",
  gulp.series(
    "clean_tmp",
    "build",
    "clean_dist",
    "move_dist",
    "assets_copy",
    "views_copy",
    "clean_tmp",
  ),
);

tsconfig.json

{
  "compilerOptions": {
    "incremental": true,
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es2018",
    "noImplicitAny": false,
    "removeComments": true,
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist/",
    "pretty": true,
    "baseUrl": ".",
    "alwaysStrict": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "traceResolution": false,
    "paths": {
      "*": ["node_modules/*", "*"]
    },
    "types": ["jest", "node"]
  },
  "include": ["src/**/*.ts"],
  "exclude": [".git", "node_modules"]
}

@rostacik
Copy link

rostacik commented Oct 4, 2019

it seems the incremental prop is the culprit here.

this worked for me :
http://quabr.com/58031957/typescript-throws-a-cannot-read-property-length-of-undefined-when-run-throug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants