While attempting to develop a project in Gulp that incorporates Typescript, I encountered an error when running npm run gulp
. The error message indicates:
[09:03:17] Using gulpfile ~/Programming/Projects/ghars/gulpfile.js
[09:03:17] Starting 'default'...
[09:03:19] 'default' errored after 2.25 s
[09:03:19] TypeError: Cannot read property 'length' of undefined
at Object.emit [as writeFile] (/home/bruhmoment/Programming/Projects/ghars/node_modules/gulp-typescript/release/compiler.js:81:33)
at Object.writeFile (/home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:12099:14)
at emitBuildInfo (/home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:86317:16)
at emitSourceFileOrBundle (/home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:86284:13)
at forEachEmittedFile (/home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:86071:28)
at Object.emitFiles (/home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:86263:9)
at emitWorker (/home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:92213:33)
at /home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:92174:66
at runWithCancellationToken (/home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:92264:24)
at Object.emit (/home/bruhmoment/Programming/Projects/ghars/node_modules/typescript/lib/typescript.js:92174:20)
npm ERR! Linux 4.15.0-62-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "gulp"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! Error: [email protected] gulp: `node node_modules/gulp/bin/gulp.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] gulp script 'node node_modules/gulp/bin/gulp.js'.
npm ERR! Ensure that you have the latest versions of node.js and npm installed.
npm ERR! If so, this issue likely stems from the ghars package,
npm ERR! not npm itself.
npm ERR! Notify the author that it doesn't work on your system:
npm ERR! node node_modules/gulp/bin/gulp.js
npm ERR! Learn how to report such issues with this project by visiting:
npm ERR! npm bugs ghars
npm ERR! Alternatively, find their contact details through:
npm ERR! npm owner ls ghars
npm ERR! Additional logging may be available above.
npm ERR! Remember to include the following file when seeking assistance:
npm ERR! /home/bruhmoment/Programming/Projects/ghars/npm-debug.log
In an effort to address this issue, I inserted a console.log
statement into typescript.js
to track which files were being processed. Despite compiling what appeared to be all pertinent files, the error persisted. Given my limited experience with Typescript, I am uncertain about the necessary steps to rectify this hurdle.
My gulpfile.js is structured as follows:
var gulp = require('gulp');
var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json');
gulp.task('default', function () {
return tsProject.src()
.pipe(tsProject())
.js.pipe(gulp.dest('dist'));
});
The contents of my tsconfig.json are outlined below:
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "./",
"allowJs": true,
"incremental": true,
"target": "es5",
"removeComments": true,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": false
},
"include": [
"server"
]
}