我正试图在使用create-react应用程序创建的react应用程序中包含一个css动画svg。代码看起来或多或少是这样的:
import Bla from './animaded_css.svg'
[...]
<Bla/>
然而,我得到了这个错误:
Error: Expected node, got `#ekE9RuALNbm6 {animation: ekE9RuALNbm6_c_o 3000ms linear infinite normal forwards}@keyframes ekE9RuALNbm6_c_o { 0% {opacity: 1} 16.666667% {opacity: 1;animation-timing-function: cubic-bezier(0.42,0,1,1)} 33.333333% {opacity: 0;animation-timing-function: cubic-bezier(0.42,0,1,1)} 66.666667% {opacity: 0;animation-timing-function: cubic-bezier(0.42,0,1,1)} 83.333333% {opacity: 1} 100% {opacity: 1}} #ekE9RuALNbm7 {animation: ekE9RuALNbm7_c_o 3000ms linear infinite normal forwards}@keyframes ekE9RuALNbm7_c_o { 0% {opacity: 1;animation-timing-function: cubic-bezier(0.42,0,1,1)} 16.666667% {opacity: 0;animation-timing-function: cubic-bezier(0.42,0,1,1)} 50% {opacity: 0;animation-timing-function: cubic-bezier(0.42,0,1,1)} 66.666667% {opacity: 1} 100%
{opacity: 1}} #ekE9RuALNbm8 {animation: ekE9RuALNbm8_c_o 3000ms linear infinite normal forwards}@keyframes ekE9RuALNbm8_c_o { 0% {opacity: 1} 33.333333% {opacity: 1;animation-timing-function: cubic-bezier(0.42,0,1,1)} 50% {opacity: 0;animation-timing-function: cubic-bezier(0.42,0,1,1)} 83.333333% {opacity: 0;animation-timing-function: cubic-bezier(0.42,0,1,1)} 100% {opacity: 1}}`
at one (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astlibone.js:12:11)
at all (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astliball.js:20:37)
at element (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astlibhandlers.js:51:37)
at one (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astlibone.js:19:10)
at all (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astliball.js:20:37)
at element (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astlibhandlers.js:51:37)
at one (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astlibone.js:19:10)
at all (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astliball.js:20:37)
at root (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astlibhandlers.js:20:54)
at one (C:codeTestsappnode_modulesreact-scriptsnode_modules@svgrhast-util-to-babel-astlibone.js:19:10)
@ ./src/App.tsx 6:0-35 14:38-41
@ ./src/index.tsx 7:0-24 12:33-36
但是,我可以直接在浏览器中显示图像,所以我想.svg文件本身没有致命的问题。
我安装了file-loader
和@svgr/webpack
,但得到了相同的错误。
问题是<svg>
中<style>
的内容被封装在<[CDATA
中。显然(有些?(浏览器可以处理它,但React不能。