【发布时间】:2020-01-24 04:03:58
【问题描述】:
我有一个用打字稿写的网络工作者。它从命令行编译得很好。然而,当我尝试在 Gulp 中编译它时,我得到了奇怪的类型错误:
/.../node_modules/@types/hls.js/index.d.ts(357,17): error TS2304: Cannot find name 'SourceBuffer'.
/.../node_modules/@types/hls.js/index.d.ts(1716,27): error TS2304: Cannot find name 'AudioTrack'.
... (more like that)
我不知道这些类型是从哪里来的;但是我认为它与父目录中的node_modules/@types(运行gulpfile.js)有关,但我不知道为什么打字稿编译器会在那里寻找。我的 gulpfile 的(希望)相关部分是:
const ts = require('gulp-typescript');
const tsWorkerProject = ts.createProject('src/app/workers/tsconfig.json');
// stuff...
const compileWorkers = (done) => {
return tsWorkerProject.src()
.pipe(tsWorkerProject())
.js.pipe(gulp.dest(paths.dist))
.on('error', err => {
console.error(err.toString());
done(err);
});
};
// more stuff...
我在工作目录中有tsconfig.json:
{
"compilerOptions": {
"lib": ["webworker", "ScriptHost", "ES2018"],
"importHelpers": true,
"target": "es5",
"jsx": "react",
"sourceMap": true,
"inlineSources": true,
"diagnostics": true,
},
"files": ["./*.ts"],
}
【问题讨论】:
标签: typescript gulp web-worker