'Rollup is importing util

I am building a library to be used to call api's

I am using rollup to bundle all the files into one file, the issue is its adding this line

import util from 'util';

not sure what it does, I am not using anything from util

below is my rollup config file

import nodeGlobals from "rollup-plugin-node-globals";
import commonjs from "rollup-plugin-commonjs";
import uglify from "rollup-plugin-uglify";
import babel from "rollup-plugin-babel";
import replace from "rollup-plugin-replace";
import resolve from "rollup-plugin-node-resolve";
import rollupJson from "rollup-plugin-json";

export default [
    {
        input: 'src/config.js',
        output: [
            {
                name:"asd",
                file: 'dist/bundle-b2.js',
                format: 'es',
            }
        ],
        plugins: [
            babel({
                babelrc: false,
                presets: [
                    ["airbnb",{"modules":false}],
                    ["env",{"modules":false,"useBuiltIns": false}],
                    ["es2015",{"modules":false}],
                    ['stage-2']],
                exclude:[
                    'node_modules/**',
                ],
                plugins: ['external-helpers', ["transform-builtin-extend", {
                    globals: ["Error", "Array"],
                }]],
                externalHelpers: true,
                runtimeHelpers: true,

            }),
            resolve({
                jsnext: true,
                preferBuiltins: true,
                browser: true,
            }),
            commonjs({
                include: 'node_modules/**'
            }),
            nodeGlobals(
                {
                    process:true,
                    global:false,
                    Buffer:false
                }
            ),

            rollupJson({compact: true
            }),

            replace({
                'process.env.NODE_ENV': JSON.stringify('production'),
            }),
        ]
    }
];

any help please ?

Thanks



Solution 1:[1]

Probably what is happening is one of your dependencies uses NodeJS's util built-in library. Even though you don't use util and you might not even use functionality from that dependency that uses util, Rollup still adds the import to the bundle.

If that is indeed the case, you'll need another plugin (like rollup-plugin-polyfill-node) that can handle these imports and give you something that either mimics or at least fakes functionality so that the build can complete properly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tanner Stern