nextjs IE11 對(duì)象不支持“attachShadow”屬性或方法

報(bào)錯(cuò):SCRIPT438: 對(duì)象不支持“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

// 如果報(bào) shadydom.min.js
import '@webcomponents/webcomponentsjs';
import '@webcomponents/shadydom';
// 如果報(bào) trunc 
import 'core-js/features/math/trunc';

備注
1、 nextjs 內(nèi)置 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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容