Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
babinik opened this issue Oct 24, 2024 · 2 comments
Open

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

babinik opened this issue Oct 24, 2024 · 2 comments

Comments

@babinik
Copy link

babinik commented Oct 24, 2024

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
Copy link
Owner

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
Copy link
Owner

zloirock commented Nov 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants