美文网首页
nextjs IE11 对象不支持“attachShadow”属

nextjs IE11 对象不支持“attachShadow”属

作者: Axiba | 来源:发表于2020-08-11 11:07 被阅读0次

    报错:SCRIPT438: 对象不支持“attachShadow”属性或方法

    1、
    package.json

    // +
    "@webcomponents/shadydom": "^1.7.4",
     "next-transpile-modules": "^4.0.2",
    

    2、next.config.js

    const withTM = require('next-transpile-modules');
    // ...
        const originalEntry = config.entry;
        config.entry = async () => {
          const entries = await originalEntry();
          // add custom polyfills into specific next.js bundle
          // https://github.com/zeit/next.js/issues/10794
          const nextPolyfillPath = 'static/runtime/polyfills.js';
          const nextPolyfills = entries[nextPolyfillPath];
          if (nextPolyfills) {
            entries[nextPolyfillPath] = [
              nextPolyfills,
              './src/client/polyfills.js',
            ];
          }
          return entries;
        };
    // ...
    module.exports = withPlugins(
      [withTM],
      nextConfig,
    );
    

    3、add src/client/polyfills.js

    // 如果报 shadydom.min.js
    import '@webcomponents/webcomponentsjs';
    import '@webcomponents/shadydom';
    // 如果报 trunc 
    import 'core-js/features/math/trunc';
    
    

    备注
    1、 nextjs 内置 polyfill :https://github.com/vercel/next.js/blob/0923ee6db49c20e1f28363199caf176f164d05b7/packages/next-polyfill-nomodule/src/index.js

    2、core.js :https://github.com/zloirock/core-js/tree/master/packages/core-js/features

    3、https://github.com/webcomponents/polyfills

    相关文章

      网友评论

          本文标题:nextjs IE11 对象不支持“attachShadow”属

          本文链接:https://www.haomeiwen.com/subject/hqyedktx.html