![](/img/trans.png)
[英]TypeScript error "TS2354: This syntax requires an imported helper but module 'tslib' cannot be found"
[英]How can I silence the TS2354 error message in TypeScript 2.1.4?
我收到错误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.
主要
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'] }
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.