编译 typescript web worker 从命令行工作,而不是从 gulp
Compiling typescript web worker works from command line but not from gulp
我有一个用打字稿写的网络工作者。它从命令行编译得很好。然而,当我尝试在 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"],
}
事实证明,答案是在 compilerOptions
下包含一个空的 types
数组。我的工作 tsconfig.json
看起来像:
{
"compilerOptions": {
"lib": ["webworker", "scripthost", "ES2015"],
"importHelpers": true,
"target": "es2015",
"jsx": "react",
"sourceMap": true,
"inlineSources": true,
"diagnostics": true,
"types": [],
},
"files": ["./*.ts"],
}
我有一个用打字稿写的网络工作者。它从命令行编译得很好。然而,当我尝试在 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"],
}
事实证明,答案是在 compilerOptions
下包含一个空的 types
数组。我的工作 tsconfig.json
看起来像:
{
"compilerOptions": {
"lib": ["webworker", "scripthost", "ES2015"],
"importHelpers": true,
"target": "es2015",
"jsx": "react",
"sourceMap": true,
"inlineSources": true,
"diagnostics": true,
"types": [],
},
"files": ["./*.ts"],
}