Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollup with gulp and typescript outputs Cannot find module 'tslib/tslib.es6.js'

Tags:

rollupjs

I followed the typescript gulp in the doc :https://rollupjs.org/guide/en#gulp

here is my gulp file :

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)

Anyone knows why this is happening is this a bug with rollup or am I doing something wrong?

like image 964
Steven Avatar asked Apr 30 '19 17:04

Steven


People also ask

How to solve the cannot find module 'typescript' error?

To solve the cannot find module 'typescript' error, make sure to install typescript globally by running the npm i -g typescript command and create a symbolic link from the globally-installed package to node_modules by running the npm link typescript command. Open your terminal in your project's root directory and run the following commands:

How to run TypeScript compiler in rollup using rimraf?

} rimraf dist, will make sure to clean up the output directory for Rollup: dist tsc, will run the TypeScript compiler through the configurations defined in tsconfig.json file. The output content will be located in the ./out-tsc directory, as defined in the TypeScript configuration file.

How to integrate typescript with rollup?

In case you're planning to build a SPA project ( Single Page Application ), you can use the createSpaConfig in Rollup configuration. Also, you can install the @rollup/plugin-typescript for seamless integration between Rollup and TypeScript. The @rollup/plugin-typescript will load any compilerOptions from the tsconfig.json file by default.

Is it possible to configure the TypeScript compiler to handle modules?

With the common TypeScript modules problems highlighted, and solutions provided in this post, I hope that it will become a bit easier to configure the TypeScript compiler to handle modules in your TypeScript projects. Hopefully you’ve found this post informative and helpful.


1 Answers

You need tslib, which is a peer dependency of rollup-plugin-typescript.

npm i -D tslib
like image 72
Steve Avatar answered Oct 18 '22 02:10

Steve