rollup-plugin-typescript2: Cannot import plugin with `ts-node`

I am using this in a gulp to compile using gulp-better-rollup when importing it uses the typings from dist and loads rollup-plugin-typescript2.cjs.js

However rollup does not export the default as default in cjs

Using

import typescript from "rollup-plugin-typescript2"

results in TypeError: rollup_plugin_typescript2_1.default is not a function.

To work around this I have had to import like this

import * as typescript from "rollup-plugin-typescript2"

Then cast as any to invoke.

plugins: [
        (typescript as any)()
]

Also the interface for the options does not match the documentation, as the typeings has the options object as required and all properties as required.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16 (10 by maintainers)

Most upvoted comments

Looks like there are bunch of workarounds, closing for now.

If you use a gulpfile.ts, using typescript 2.8 and "esModuleInterop": true option you can import this with

import typescript from "rollup-plugin-typescript2";

enabling this option, can change other import behaviours (if an import fails at runtime try removing * as from that import, or adding it).

Yup, I find this to be a frequent issue with interoperability between Typescript’s and Rollup’s interpretations of the module system.

Two ways to fix it:

  • Consumers can set this compilerOption to true in their tsconfig.json: allowSyntheticDefaultImports: true
  • rollup-plugin-typescript2 could offer both a named and a default export of the transformer function.