使用gulp和打字稿输出进行汇总找不到模块'tslib / tslib.es6.js'

时间:2019-04-30 17:04:41

标签: rollupjs

我遵循了文档中的打字稿gulp:https://rollupjs.org/guide/en#gulp

这是我的gulp文件:

const gulp = require("gulp");
const rollup = require("rollup");
const rollupTypescript = require("rollup-plugin-typescript");

gulp.task("build", () => {
  return rollup
    .rollup({
      input: "./main.ts",
      plugins: [rollupTypescript()]
    })
    .then(bundle => {
      return bundle.write({
        file: "./main.js",
        format: "umd",
        name: "library",
        sourcemap: true
      });
    });
});
Error: Cannot find module 'tslib/tslib.es6.js' from 'C:\projets\Tests\rollup\node_modules\rollup-plugin-typescript\dist'
    at Function.module.exports [as sync] (C:\projets\Tests\rollup\node_modules\resolve\lib\sync.js:58:15)
    at typescript (C:\projets\Tests\rollup\node_modules\rollup-plugin-typescript\dist\rollup-plugin-typescript.cjs.js:109:29)
    at gulp.task (C:\projets\Tests\rollup\gulpfile.js:9:17)
    at taskWrapper (C:\projets\Tests\rollup\node_modules\undertaker\lib\set-task.js:13:15)
    at bound (domain.js:301:14)
    at runBound (domain.js:314:12)
    at asyncRunner (C:\projets\Tests\rollup\node_modules\async-done\index.js:55:18)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

任何人都知道为什么会这样,这是汇总错误还是我做错了什么?

1 个答案:

答案 0 :(得分:1)

您需要tslib,它是rollup-plugin-typescript中的peer dependency

npm i -D tslib