zloirock / core-js

Standard Library
MIT License
24.59k stars 1.65k forks source link

Vite with @rollup/plugin-babel - TypeError: Illegal invocation #1376

Open babinik opened 1 month ago

babinik commented 1 month ago

Good day.

Running @rollup/plugin-babel I got TypeError: Illegal invocation. Did I miss something in the configuration?

Running core-js (v3.38.1) polyfills throws Illegal invocation error.

core-js-illegal-invocation

document-create-element.js:5 Uncaught TypeError: Illegal invocation
    at document-create-element.js:5:27
    at insightR.js?buildNumber=27862be8457d+:1:175
    at insightR.js?buildNumber=27862be8457d+:1:194

Vite configuration using @rollup/plugin-babel

vite.config.js

import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from "vite";
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default defineConfig({
    build: {
        outDir: path.resolve(__dirname, '../js/provider'),
        sourcemap: true,
        emptyOutDir: true,
        copyPublicDir: false,        
        manifest: false,

        rollupOptions: {
            input: path.resolve(__dirname, 'src/insightR.ts'),

            plugins: [
                commonjs(),

                babel({
                    extensions: ['.js', '.ts'],
                    babelHelpers: 'runtime',
                    plugins: [
                        ['@babel/plugin-transform-runtime', { useESModules: true }]
                    ],
                    presets: [
                        [
                            '@babel/preset-env',
                            {                                
                                useBuiltIns: 'usage',
                                corejs: '3.38.1',
                                targets: 'safari 13, last 3 major versions, not dead',
                                modules: false
                            },
                        ],
                    ],
                })
            ]
        },

        lib: {
            entry: path.resolve(__dirname, 'src/insightR.ts'),
            name: 'insightR',
            formats: ['umd'],
            fileName: (format, entryName) => {
                if (format === 'umd') return entryName + '.js';
                return entryName;
            }
        }
    }
})

Checked in browsers: Chrome 130.0.6723.70, Edge 130.0.2849.52

zloirock commented 1 month ago

That's strange. It's just access to window.document and this is the first time I've heard that it could throw an error anywhere. I'll take a look at this a little later.

zloirock commented 3 weeks ago

Sorry, I can't reproduce it. Could you create a repo with a minimal reproducible example?