报错: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
网友评论