{"id":21904,"library":"rollup-jest","title":"rollup-jest","description":"Rollup preprocessor for Jest that transforms files using Rollup. Current version 3.1.0, actively maintained. Allows using Rollup plugins and configuration in Jest tests, supporting ES modules. Key differentiator: integrates Rollup's bundling and plugin ecosystem into Jest's transform pipeline, enabling features like plugin injection, caching, and custom resolve behavior. Peer dependency on Rollup ^2.3.0 || ^3. Provides preset for zero-config setup. Suitable for projects already using Rollup who want to reuse rollup config in tests.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/ambar/rollup-jest","tags":["javascript","jest","rollup","testing"],"install":[{"cmd":"npm install rollup-jest","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-jest","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-jest","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for code transformation","package":"rollup","optional":false}],"imports":[{"note":"Used as a Jest preset, not imported directly.","wrong":"Using require('rollup-jest') in jest config","symbol":"default (preset)","correct":"// In jest.config.json: \"preset\": \"rollup-jest\""},{"note":"Configured in Jest's transform field, not imported in user code.","wrong":"Trying to import rollup-jest as a module in test files","symbol":"transform entry","correct":"// In jest.config.json: \"transform\": { \"\\\\.m?js$\": \"rollup-jest\" }"},{"note":"Options are passed as array in Jest transform config.","wrong":"Passing options as second argument to import statement","symbol":"with options","correct":"// In jest.config.json: \"transform\": { \"\\\\.js$\": [\"rollup-jest\", {\"configFile\": \"./rollup.config.js\"}] }"}],"quickstart":{"code":"npm install rollup-jest rollup --save-dev\n# jest.config.json\n{\n  \"jest\": {\n    \"preset\": \"rollup-jest\"\n  }\n}\n# __tests__/example.test.js\nimport path from 'path';\ntest('parses extname', () => {\n  expect(path.extname('foo.md')).toBe('.md');\n});","lang":"javascript","description":"Install, configure preset, and write ES module test with default import."},"warnings":[{"fix":"Upgrade Rollup to ^2.3.0 or ^3 if using rollup-jest v3.","message":"Version 3 requires Rollup ^2.3.0 or ^3. Version 2 required Rollup ^1.0.0.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Set 'useCache: false' if experiencing stale results.","message":"The 'useCache' option may cause issues with plugins that have state (e.g. TypeScript).","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Run Jest with NODE_OPTIONS=--experimental-vm-modules npm run test","message":"To use ESM configFile with Rollup v3, you must add --experimental-vm-modules to Node.js flags.","severity":"gotcha","affected_versions":">=3.0.0 <4"},{"fix":"Add a custom transform pattern for other extensions, e.g. \"\\\\.ts$\": \"rollup-jest\"","message":"Default transform only matches .mjs and .js files. Other extensions like .ts or .jsx are not transformed unless explicitly added.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"npm install rollup-jest rollup --save-dev","cause":"rollup-jest not installed or not in devDependencies","error":"Cannot find module 'rollup-jest'"},{"fix":"Add rollup-jest to Jest transform in jest.config.json","cause":"Jest not configured to transform the file with rollup-jest","error":"Cannot use import statement outside a module"},{"fix":"Ensure the file extension matches the regex in Jest config (e.g., \"\\\\.m?js$\")","cause":"File not transformed because transform pattern doesn't match","error":"Jest encountered an unexpected token - SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}