【问题标题】:Compiling typescript web worker works from command line but not from gulp编译 typescript web worker 从命令行工作,而不是从 gulp
【发布时间】: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


    【解决方案1】:

    事实证明,答案是在compilerOptions 下包含一个空的types 数组。我的工作 tsconfig.json 看起来像:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-10
      • 2013-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      相关资源
      最近更新 更多