ckeditor craco设置中的iConview发生错误
我正在设置Craco,以在CRA中使用Ckeditor。我一直在IconView中遇到错误。 修改正则不改变任何东西。
该设置文件在其他现有项目中使用时正常工作,但是在新项目中继续发生错误。 我想知道是什么原因导致了这个错误。
craco.config.js
const CKEditorWebpackPlugin = require("@ckeditor/ckeditor5-dev-webpack-plugin");
const { styles } = require("@ckeditor/ckeditor5-dev-utils");
module.exports = {
webpack: {
configure: (config, { env, paths }) => {
config.plugins.push(
new CKEditorWebpackPlugin({
language: "ko",
addMainLanguageTranslationsToAllAssets: true,
})
);
const regExpThemeIconSvg =
/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/;
const regExpThemeCss = /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css/;
const cssRegex = /\.css$/;
const cssModuleRegex = /\.module\.css$/;
config.module.rules.push(
{ test: regExpThemeIconSvg, use: ["raw-loader"] },
{
test: regExpThemeCss,
use: [
{
loader: "style-loader",
// options: { injectType: "singletonStyleTag" }
},
{
loader: "postcss-loader",
options: styles.getPostCssConfig({
themeImporter: {
themePath: require.resolve("@ckeditor/ckeditor5-theme-lark"),
},
minify: true,
}),
},
],
}
);
config.module.rules.forEach((rule) => {
if (rule.oneOf) {
rule.oneOf.forEach((subRule) => {
if (String(subRule.test) === String(cssRegex)) {
subRule.exclude = [cssModuleRegex, regExpThemeCss];
}
if (String(subRule.test) === String(cssModuleRegex)) {
subRule.exclude = [regExpThemeCss];
}
if (
String(subRule.loader).includes("file-loader") &&
Array.isArray(subRule.exclude)
) {
subRule.exclude.push(regExpThemeIconSvg, regExpThemeCss);
}
});
}
});
return config;
},
},
};
错误日志
react_devtools_backend.js:3973 TypeError: Cannot read properties of null (reading 'getAttribute')
at IconView._updateXMLContent (iconview.js:100:1)
at IconView.render (iconview.js:76:1)
at IconView.<anonymous> (observablemixin.js:258:1)
at IconView.fire (emittermixin.js:200:1)
at IconView.<computed> [as render] (observablemixin.js:262:1)
at ViewCollection._renderViewIntoCollectionParent (viewcollection.js:204:1)
at ViewCollection.<anonymous> (viewcollection.js:65:1)
at ViewCollection.fire (emittermixin.js:200:1)
at ViewCollection.addMany (collection.js:220:1)
at ViewCollection.add (collection.js:185:1) {phase: 'initialization', willEditorRestart: false}
I am setting up craco to use CKEditor in CRA. I keep getting an error in Iconview.
Modifying the regex didn't change anything.
This setting file worked normally when used in other existing projects, but errors continue to occur in new projects.
I would like to know what is causing this error.
craco.config.js
const CKEditorWebpackPlugin = require("@ckeditor/ckeditor5-dev-webpack-plugin");
const { styles } = require("@ckeditor/ckeditor5-dev-utils");
module.exports = {
webpack: {
configure: (config, { env, paths }) => {
config.plugins.push(
new CKEditorWebpackPlugin({
language: "ko",
addMainLanguageTranslationsToAllAssets: true,
})
);
const regExpThemeIconSvg =
/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/;
const regExpThemeCss = /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css/;
const cssRegex = /\.css$/;
const cssModuleRegex = /\.module\.css$/;
config.module.rules.push(
{ test: regExpThemeIconSvg, use: ["raw-loader"] },
{
test: regExpThemeCss,
use: [
{
loader: "style-loader",
// options: { injectType: "singletonStyleTag" }
},
{
loader: "postcss-loader",
options: styles.getPostCssConfig({
themeImporter: {
themePath: require.resolve("@ckeditor/ckeditor5-theme-lark"),
},
minify: true,
}),
},
],
}
);
config.module.rules.forEach((rule) => {
if (rule.oneOf) {
rule.oneOf.forEach((subRule) => {
if (String(subRule.test) === String(cssRegex)) {
subRule.exclude = [cssModuleRegex, regExpThemeCss];
}
if (String(subRule.test) === String(cssModuleRegex)) {
subRule.exclude = [regExpThemeCss];
}
if (
String(subRule.loader).includes("file-loader") &&
Array.isArray(subRule.exclude)
) {
subRule.exclude.push(regExpThemeIconSvg, regExpThemeCss);
}
});
}
});
return config;
},
},
};
error log
react_devtools_backend.js:3973 TypeError: Cannot read properties of null (reading 'getAttribute')
at IconView._updateXMLContent (iconview.js:100:1)
at IconView.render (iconview.js:76:1)
at IconView.<anonymous> (observablemixin.js:258:1)
at IconView.fire (emittermixin.js:200:1)
at IconView.<computed> [as render] (observablemixin.js:262:1)
at ViewCollection._renderViewIntoCollectionParent (viewcollection.js:204:1)
at ViewCollection.<anonymous> (viewcollection.js:65:1)
at ViewCollection.fire (emittermixin.js:200:1)
at ViewCollection.addMany (collection.js:220:1)
at ViewCollection.add (collection.js:185:1) {phase: 'initialization', willEditorRestart: false}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我和你遇到了同样的问题,我花了很长时间才能理解发生了什么。就我而言,也许您的情况与React-Scripts软件包版本有关。最近的反应录版本&gt; 4.0.3,将丢弃此错误。您可以降级包装,也可以使用我创建的此“插件”:
gist: https://gist.github.com/william-takayama/6b2a7e4b0b9497ee59fa4ba60bba60bed2e6d0
I had the same issue as you, and it took me quite a while to understand what was happening. In my case, and probably yours it's related with react-scripts package version. Recent react-script version > 4.0.3, will throw this error. You can either downgrade your package, or use this "plugin" that I had created:
GIST: https://gist.github.com/william-takayama/6b2a7e4b0b9497e59fa4ba60bed2e6d0