Function.prototype.toString issues in IE11 Svelte/Babel/Rollup

回眸只為那壹抹淺笑 提交于 2021-02-08 07:22:00

问题


My current rollup.config.js is

    commonjs(),
    babel({
                extensions: ['.js', '.mjs', '.html', '.svelte'],
                runtimeHelpers: true,
                exclude: ['node_modules/@babel/**', 'node_modules/core-js/**' ], // <= /!\ NOT 'node_mobules/**'
                presets: [
                    ['@babel/preset-env', {
                    // adapter to ensure IE 11 support
                    targets: '> 0.25%, not dead, IE 11',
                    "modules": false,
                    "spec": true,
                    "forceAllTransforms": true,
                    useBuiltIns: 'usage',
                    corejs: 3
                    }]
                ],
                plugins: [
                    '@babel/plugin-syntax-dynamic-import',
                    [
                        '@babel/plugin-transform-runtime',
                        {
                            useESModules: true
                        }
                    ]
                ]
              })

Getting issue in IE11:

Function.prototype.toString: "this" is not a Function object

How to correctly fix that issue?

I have tried to

  • import webcomponents into my main.js:

    import 'node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js';

    But this file is not being imported:

    Unresolved dependencies https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js (imported by src\main.js)

This means i have to config resolve-plugin but it seems to be incorrect way because it is marked as non-used then.


回答1:


Correctly working rollup.config

commonjs(),
babel({
    extensions: ['.js', '.mjs', '.html', '.svelte'],
    runtimeHelpers: true,
    exclude: ['node_modules/@babel/**', 'node_modules/core-js/**' ], 
    presets: [
        ['@babel/preset-env', {
        targets: {
            browsers: [
                "> 0.25%"
                ,"not dead"
                ,"IE 11"
            ]
        },
        "modules": false,
        "spec": true,
        "forceAllTransforms": true,
        useBuiltIns: 'usage',
        corejs: 3
        }]
    ],
    plugins: [
        '@babel/plugin-syntax-dynamic-import',
        [
            '@babel/plugin-transform-runtime',
            {
                useESModules: true
            }
        ]
    ]
}),
polyfill(['@webcomponents/webcomponentsjs'])

the polyfill one is rollup-plugin-polyfill



来源:https://stackoverflow.com/questions/59374688/function-prototype-tostring-issues-in-ie11-svelte-babel-rollup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!