Skip to content
Latchkey

Rollup "Unexpected token (Note that you need plugins ...)"

Rollup parses plain JavaScript out of the box. When it meets JSX, TypeScript, JSON, or CSS without a plugin to handle it, it stops with "Unexpected token" and a note that you need a plugin for non-JS files.

What this error means

A Rollup build (or a tool built on Rollup) fails with Unexpected token and the hint "Note that you need plugins to import files that are not JavaScript." It points at JSX or a non-JS import.

rollup output
[!] (plugin commonjs--resolver) RollupError: Unexpected token (5:9) in /app/src/App.jsx
Note that you need plugins to import files that are not JavaScript
  3: function App() {
  4:   return (
  5:     <div className="app">
              ^

Common causes

No plugin for JSX/TS syntax

Rollup needs @rollup/plugin-babel, @rollup/plugin-typescript, or an esbuild/swc plugin to parse JSX/TS. Without one, the < of JSX is an unexpected token.

Importing JSON/CSS/assets without a plugin

Importing .json needs @rollup/plugin-json; CSS/asset imports need their own plugins. Otherwise Rollup parses the file content as JavaScript.

How to fix it

Add the plugin for the syntax/file type

Register the plugin that teaches Rollup to handle the file.

rollup.config.js
// rollup.config.js
import babel from '@rollup/plugin-babel'
import json from '@rollup/plugin-json'
export default {
  plugins: [
    babel({ babelHelpers: 'bundled', extensions: ['.js', '.jsx', '.ts', '.tsx'] }),
    json(),
  ],
}

Order resolution plugins correctly

  1. Put @rollup/plugin-node-resolve and @rollup/plugin-commonjs before transform plugins.
  2. Set the transform plugin's extensions to include .jsx/.tsx.
  3. Confirm the file extension matches a configured plugin.

How to prevent it

  • Add Rollup plugins for every non-plain-JS file type you import.
  • Keep plugin extensions lists aligned with your source files.
  • Order node-resolve/commonjs before transform plugins.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →