我有一个演示项目,我要使用启用的ES2015模块并将其用于外部TS帮助器的tslib编译为ES5:

package.json

{
  "name": "foo",
  "scripts": {
    "build": "tsc"
  },
  "dependencies": {
    "tslib": "^1.9.3"
  },
  "devDependencies": {
    "typescript": "^3.1.3"
  }
}

tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "outDir": "./lib",
    "rootDir": "./src",
    "importHelpers": true,
    "strict": true,
    "experimentalDecorators": true
  }
}

src / index.ts
function a(target: any) {
    return target;
}

@a
export class Foo {}

这会导致错误:



正确编译lib/index.js时:
import * as tslib_1 from "tslib";
function a(target) {
    return target;
}
var Foo = /** @class */ (function () {
    function Foo() {
    }
    Foo = tslib_1.__decorate([
        a
    ], Foo);
    return Foo;
}());
export { Foo };

这个问题怎么解决?

最佳答案

Noob错误(我刚刚犯了)。尝试:

npm install tslib

要么
npm i

在周五退出之前,我个人做了git clean -fxd,但是没有npm i,所以所有npm软件包都丢失了。 h!

关于typescript - “This syntax requires an imported helper but module ' tslib ' cannot be found”与ES2015模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52801814/

10-12 12:57