stack twitter tryhackme rss linkedin cross

Wilco van Esch

Skip to main content

Search results

    Peer dependency conflict from the rollup-plugin-terser package

    Problem

    You get an error like this during your build step's npm install:

    npm ERR! code ERESOLVE
    npm ERR! ERESOLVE could not resolve
    npm ERR!
    npm ERR! While resolving: rollup-plugin-terser@7.0.2
    npm ERR! Found: rollup@3.2.2
    npm ERR! node_modules/rollup
    Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
    npm ERR!   dev rollup@"3.2.2" from the root project
    npm ERR!   peerOptional rollup@"^2.78.0||^3.0.0" from @rollup/plugin-node-resolve@15.0.0
    npm ERR!   node_modules/@rollup/plugin-node-resolve
    npm ERR!     dev @rollup/plugin-node-resolve@"15.0.0" from the root project
    npm ERR!
    npm ERR! Could not resolve dependency:
    npm ERR! peer rollup@"^2.0.0" from rollup-plugin-terser@7.0.2
    npm ERR! node_modules/rollup-plugin-terser
    npm ERR!   dev rollup-plugin-terser@"7.0.2" from the root project
    npm ERR!
    npm ERR! Conflicting peer dependency: rollup@2.79.1
    npm ERR! node_modules/rollup
    npm ERR!   peer rollup@"^2.0.0" from rollup-plugin-terser@7.0.2
    npm ERR!   node_modules/rollup-plugin-terser
    npm ERR!     dev rollup-plugin-terser@"7.0.2" from the root project
    npm ERR!
    npm ERR! Fix the upstream dependency conflict, or retry
    npm ERR! this command with --force or --legacy-peer-deps
    npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
    npm ERR!
    npm ERR!
    npm ERR! For a full report see:
    npm ERR! /opt/buildhome/.npm/_logs/2023-02-04T13_38_32_938Z-eresolve-report.txt
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /opt/buildhome/.npm/_logs/2023-02-04T13_38_32_938Z-debug-0.log

    Cause

    In your project you're requiring the latest version of rollup (3.2.2 at the time of writing), whereas one of your other dependencies (the library rollup-plugin-terser) requires a rollup major version of 2.

    Solution

    Replace the no longer maintained rollup-plugin-terser with @rollup/plugin-terser. Specifically, create a new branch with the following changes and merge the changes:

    1. npm uninstall rollup-plugin-terser
    2. npm i @rollup/plugin-terser --save-dev
    3. In your rollup config, replace import { terser } from "rollup-plugin-terser"; with import terser from "@rollup/plugin-terser"; (removing the curly brackets matters, as the new package uses a default export).