Plugins: [!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

Created on 18 Apr 2020  ·  3Comments  ·  Source: rollup/plugins

  • Rollup Plugin Name: @rollup/plugin-typescript
  • Rollup Plugin Version: 4.1.1
  • Rollup Version: 2.6.1
  • Operating System (or Browser): windows 10
  • Node Version: 6.14.4

How Do We Reproduce?

local build
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

repls build
https://repl.it/repls/TrimScornfulApplicationframework

The "buildStart" hook used by the output plugin typescript is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.

Expected Behavior

Build multiple versions

Actual Behavior

Build fail
error: [!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)

x⁸ ⋅ wontfix 🔌 plugin-typescript

All 3 comments

As the warning states, yes, this plugin cannot be used as an output plugin. You need to specify the plugins option at the top level.

@lukastaegert
I want to compile multiple plug-ins at one time. What should I do with different plugins?

_Currently, rollup or @rollup/plugin-typescript does not support this syntax_

export default {
    input: "src/index.ts",
    output: [
        {
            file: `dist/${name}.esm.js`,
            format: "es",
            plugins: [typescript()],
        },
        {
            file: `dist/${name}.min.js`,
            format: "es",
            plugins: [babel(), typescript()],
        },
    ],
};

export default {
    input: "src/index.ts",
        plugins: [typescript()],
    output: [
        {
            file: `dist/${name}.esm.js`,
            format: "es"
        },
        {
            file: `dist/${name}.min.js`,
            format: "es",
            plugins: [babel()],
        },
    ],
};

The TypeScript plugin MUST run before Rollup processes files so it MUST be an input plugin. Per-output plugins can only run AFTER Rollup has processed files, and Rollup does not understand TypeScript.
But note that you also need the @rollup/plugin-babel@next to run this one per output, and you need to configure it in a special way.

Was this page helpful?
0 / 5 - 0 ratings