当通过gulp运行时,Typescript抛出“无法读取未定义的属性'length'的信息”

时间:2019-09-20 16:15:02

标签: typescript npm gulp

我正在尝试在Gulp中使用Typescript构建项目。但是,当我尝试执行npm run gulp时,会引发以下错误:

[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! ghars@1.0.0 gulp: `node node_modules/gulp/bin/gulp.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ghars@1.0.0 gulp script 'node node_modules/gulp/bin/gulp.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ghars package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node node_modules/gulp/bin/gulp.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ghars
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ghars
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/bruhmoment/Programming/Projects/ghars/npm-debug.log

我尝试在console.log中放入typescript.js语句以查看正在处理的文件,但似乎所有明显的文件都已编译。我不确定要解决此错误该怎么做,因为我不熟悉Typescript。

这是我的gulpfile.js:

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'));
});

这是我的tsconfig.json:

{
  "compilerOptions": {
    "outDir": "dist",
    "rootDir": "./",
    "allowJs": true,
    "incremental": true,
    "target": "es5",
    "removeComments": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "strict": true,
    "strictNullChecks": false
  },
  "include": [
    "server"
  ]
}

1 个答案:

答案 0 :(得分:2)

关闭“增量”:true,