编译打字稿网络工作者从命令行运行,但没有从gulp进行工作

问题描述 投票:0回答:1

我有一个用打字稿写的网络工作者。它可以从命令行编译良好。但是,当我尝试在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
1个回答
0
投票
事实证明,答案是在types下包含一个空的compilerOptions数组。我的工作tsconfig.json如下:

{ "compilerOptions": { "lib": ["webworker", "scripthost", "ES2015"], "importHelpers": true, "target": "es2015", "jsx": "react", "sourceMap": true, "inlineSources": true, "diagnostics": true, "types": [], }, "files": ["./*.ts"], }

© www.soinside.com 2019 - 2024. All rights reserved.