Registry / web-framework / rollup-plugin-svelte

rollup-plugin-svelte

JSON →
library7.2.3jsnpmunverified

Compile Svelte components with Rollup. Version 7.2.3 requires Rollup >=2.0.0 and Svelte >=3.5.0. This plugin translates .svelte files into JavaScript and CSS, and must be used alongside @rollup/plugin-node-resolve and typically @rollup/plugin-commonjs. Key features include preprocessing support, SSR compilation (generate: 'ssr'), custom element output, and flexible include/exclude filtering. The package ships TypeScript types. For new projects, the maintainers recommend using SvelteKit or Vite with vite-plugin-svelte instead.

npm install rollup-plugin-svelte
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-SVEL
R
rollup-plugin-svelte
web-frameworkjavascriptv7.2.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import svelte from 'rollup-plugin-svelte'
const svelte = require('rollup-plugin-svelte')
The plugin is a default ES module export. CommonJS require() is not supported for this package.
svelte (in rollup.config.js)
import svelte from 'rollup-plugin-svelte'
import { svelte } from 'rollup-plugin-svelte'
The plugin is a default export, not a named export. Using named import will result in undefined.
svelte function usage
plugins: [svelte({ compilerOptions: { hydratable: true } })]
plugins: [new svelte()]
svelte is a function, not a class. Do not use 'new'. It returns a plugin object.

Basic Rollup config to compile Svelte components with the plugin, node-resolve, and commonjs. Includes include filter and dev mode.

// rollup.config.js import svelte from 'rollup-plugin-svelte'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; export default { input: 'src/main.js', output: { file: 'public/bundle.js', format: 'iife', }, plugins: [ svelte({ include: 'src/**/*.svelte', compilerOptions: { dev: process.env.NODE_ENV !== 'production' }, }), resolve({ browser: true, exportConditions: ['svelte'] }), commonjs(), ], };
Debug
Known issues
breakingrollup-plugin-svelte v6 dropped support for Rollup < 1.x and Svelte < 3.x.
fix
Upgrade to Rollup 1.x/2.x+ and Svelte 3.x+.
affects: >=6.0.0
breakingv7.0.0 removed the 'css' option (custom CSS output). CSS handling is now always via emitCss.
fix
Use emitCss: true (default) or false. For custom CSS handling, use Rollup's asset pipeline.
affects: >=7.0.0
gotchaThe plugin requires @rollup/plugin-node-resolve with exportConditions: ['svelte'] to resolve Svelte components from node_modules.
fix
Add resolve({ browser: true, exportConditions: ['svelte'] }) to your rollup config.
affects: >=5.0.0
deprecatedThe 'generate' option in compilerOptions is deprecated in Svelte 4; use 'compilerOptions: { dev: boolean }' instead.
fix
For SSR, use SvelteKit or Vite; for client-side compile, omit generate or set to 'dom'.
affects: >=7.0.0
gotchaIf you see 'Error: Cannot find module 'svelte/compiler'', it's because svelte is not installed or not resolved correctly.
fix
Ensure svelte is in your devDependencies and that node_modules is accessible.
affects: >=5.0.0
Errors
Common errors & fixes
Error: Cannot find module 'rollup-plugin-svelte'
Package not installed or not in node_modules.
fix
Run 'npm install --save-dev rollup-plugin-svelte'.
Error: 'svelte' is not exported by node_modules/rollup-plugin-svelte/index.mjs
Using named import instead of default import.
fix
Use 'import svelte from 'rollup-plugin-svelte'' instead of 'import { svelte } from ...'.
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
Rollup cannot parse .svelte files without this plugin.
fix
Add rollup-plugin-svelte to your plugins list in rollup.config.js.
Error: The 'svelte' condition in exports must be used with @rollup/plugin-node-resolve's exportConditions
Missing exportConditions in node-resolve config.
fix
Add 'exportConditions: ['svelte']' to resolve plugin options.
Upgrade
Version history
7.2.3latest on npm
Audit
Dependencies
rolluprequiredPeer dependency, needed as bundler. Requires >=2.0.0.
svelterequiredPeer dependency, required for compiling Svelte components. Requires >=3.5.0.
@rollup/plugin-node-resolveoptionalPlugin resolves node_modules imports; needed to resolve Svelte components from packages with svelte export condition.
@rollup/plugin-commonjsoptionalPlugin converts CommonJS modules to ES module format; often required alongside rollup-plugin-svelte.
Agent activity
10 hits · last 30 days
node
8
Resources
rollup-plugin-svelte — npm install rollup-plugin-svelte · libregistry