【问题标题】:How can I silence the TS2354 error message in TypeScript 2.1.4?如何使 TypeScript 2.1.4 中的 TS2354 错误消息静音?
【发布时间】:2017-04-29 00:21:16
【问题描述】:

我收到 错误 TS2354:此语法需要导入的帮助程序,但找不到模块 'tslib'。 在我的 webpack 2 构建中使用 TypeScript 2.1 的新 importHelpers 选项。 捆绑包似乎按预期构建,但错误消息令人不安。 谁能指出我在这里做错了什么?还是rxjs\Subject.d.ts 的每个错误有问题(提到的行 (Subject.d.ts:9,43) 确实使用和无辜的extends 关键字)?

ts-loader: Using typescript@2.1.4 and C:Repro\stuff\tsconfig.json
Hash: f24da06626836e4fc997
Version: webpack 2.1.0-beta.28
Time: 4256ms
Asset     Size  Chunks             Chunk Names
app.js  3.01 kB       0  [emitted]  app
  [1] ./src/main.ts 372 bytes {0} [built]
    + 1 hidden modules

ERROR in C:Repro\stuff\node_modules\rxjs\Subject.d.ts
(9,43): error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

main.ts

import { Observable } from "rxjs";

Observable.timer(3000, 5000)
  .timeInterval()
  .subscribe((interval) => console.log(interval));

package.json

{
  "name": "stuff",
  "version": "1.0.0",
  "scripts": {
    "build": "webpack"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.35",
    "ts-loader": "^1.3.2",
    "typescript": "^2.1.4",
    "webpack": "^2.1.0-beta.25"
  },
  "dependencies": {
    "rxjs": "^5.0.1",
    "tslib": "^1.2.0"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "importHelpers": true,
    "target": "es5",
    "noEmitHelpers": true
  }
}

webpack.config.js

module.exports = {
  name: 'server',
  target: 'node',
  entry: { 'app': './src/main.ts' },
  output: { path: './bin/', publicPath: 'bin/', filename: '[name].js' },
  externals: { rxjs: 'commonjs rxjs' },
  module: { rules: [{ test: /\.ts$/, loader: 'ts-loader' }], },
  resolve: { extensions: ['.ts'] }
};

【问题讨论】:

  • 不应该tslib 是一个依赖项,而不是一个devDependency?
  • 确实如此。我只是移动了它,但问题仍然存在。
  • 我很遗憾现在将这个问题与 webpack 混淆了。我只是尝试了普通的旧 tsc 并且仍然得到 node_modules/rxjs/Subscriber.d.ts(13,36): error TS2354: This syntax requires an imported helper 但找不到模块 'tslib'。

标签: typescript webpack-2 ts-loader


【解决方案1】:

看起来这是在 this typescript issue 下跟踪的,应该在 TypeScript 2.1.5 中修复

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-13
    • 2013-10-15
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 2020-10-23
    • 2018-01-16
    相关资源
    最近更新 更多