typescript - 通过 gulp 运行时,Typescript 抛出“无法读取未定义的属性‘长度’”
问题描述
我正在尝试在 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"
]
}
解决方案
关闭“增量”:true,
推荐阅读
- android - 在 AdMob 广告请求中使用多个广告网络
- c# - 使用 GroupBy 根据直到相应日期的整个数据计算平均值或计数
- asp.net - 尝试使用不明确的名称解析搜索 Active Directory,但它从不返回任何内容
- javascript - array.sort() - 方法没有正常工作
- php - Woocommerce 在购物车和结帐时打印简单的产品属性,例如可变属性
- git - Confluence 可以显示来自 Bitbucket/Jenkins 服务器的分支、提交哈希和日期吗?
- oracle - 如何从 Oracle 11g 实例访问 Oracle 12c 架构
- typescript - 带有泛型的打字稿自定义限制
- c# - C# - 自定义组通过花费更多时间处理大型数据集
- excel - 使用变量名称设置工作簿