JRJurman / rollup-plugin-polyfill

Rollup Plugin to Include a Polyfill
7 stars 6 forks source link

Missing shims for Node.js built-ins (even after adding the modules to the polyfill plugin) #12

Open ssantos21 opened 1 month ago

ssantos21 commented 1 month ago

I have the following rollup.config.js file.

// rollup.config.js
const commonjs = require('@rollup/plugin-commonjs');
const resolve = require('@rollup/plugin-node-resolve');
const wasm = require('@rollup/plugin-wasm');
const polyfill = require('rollup-plugin-polyfill');

export default {
    input: 'index.js',
    output: [
        {
            file: 'dist/my-library.cjs.js',
            format: 'cjs', // CommonJS format for Node.js
        },
        {
            file: 'dist/my-library.esm.js',
            format: 'esm', // ES Module format for modern browsers
        },
        {
            file: 'dist/my-library.umd.js',
            format: 'umd', // UMD format for browsers and Node.js
            name: 'MyLibrary', // Global variable name for UMD build
            globals: {
                net: 'net',
                tls: 'tls',
                events: 'events',
                buffer: 'buffer',
                stream: 'stream',
                http: 'http',
                https: 'https',
                dns: 'dns',
                url: 'url',
                util: 'util',
                path: 'path',
                fs: 'fs'
            },
        },
    ],
    plugins: [
        resolve({ jsnext: true, preferBuiltins: true, browser: true }),
        commonjs(),
        wasm(),
        polyfill(['net', 'tls', 'events', 'buffer', 'stream', 'http', 'https', 'dns', 'url', 'util', 'path', 'fs']),
    ],
    external: ['net', 'tls', 'events', 'buffer', 'stream', 'http', 'https', 'dns', 'url', 'util', 'path', 'fs'],
};

And after building the library, I got the warning:

$ npm run build

> ml_lib@0.0.1 build
> rollup -c --bundleConfigAsCjs

index.js → dist/my-library.cjs.js, dist/my-library.esm.js, dist/my-library.umd.js...
(!) Missing shims for Node.js built-ins
Creating a browser bundle that depends on "net", "tls", "events", "buffer", "stream", "http", "https", "dns", "url", "util", "path" and "fs". You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node

What is wrong ? I don't know this module very well and this could be a configuration error. But I'm passing all external modules to the polyfill.

JRJurman commented 1 month ago

@ssantos21 admittedly, it's been a while since I've worked on this project (and even longer since I've actually used it). If you can create a minimal example repository, that would help a ton for me to look into and understand what might be not working.