Typescript выдает "Cannot read свойство 'length' of undefined" при запуске через gulp - PullRequest
0 голосов
/ 20 сентября 2019

Я пытаюсь построить проект в 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 голосов
/ 21 сентября 2019

Отключить «инкремент»: true,

...