nowa-webpack / nowa-gui

MIT License
202 stars 24 forks source link

使用脚手架引入svg图片报错 #48

Closed icoreman closed 5 years ago

icoreman commented 5 years ago

脚手架:nowa-template-salt 地址:https://github.com/nowa-webpack/template-salt 本来是想使用@svgr/webpack的,不知道怎么配。 image 不知道配得对不。 关键是一引入svg就报错 webpack: Compiled successfully. webpack: Compiling... webpack building... events.js:167 throw er; // Unhandled 'error' event ^

TypeError: Cannot read property 'replace' of undefined at C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\util\sanitize.js:31:31 at Array.forEach () at sanitizeStyleNodes (C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\util\sanitize.js:28:11) at C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\util\sanitize.js:97:17 at Array.forEach () at sanitize (C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\util\sanitize.js:90:64) at C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\util\sanitize.js:55:13 at Array.forEach () at sanitize (C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\util\sanitize.js:54:17) at C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\util\sanitize.js:100:17 Emitted 'error' event at: at Parser.exports.Parser.Parser.parseString (C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_xml2js@0.4.19@xml2js\lib\parser.js:326:16) at Parser.parseString (C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_xml2js@0.4.19@xml2js\lib\parser.js:5:59) at render (C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\index.js:69:19) at C:\Users\Administrator.nowa-gui\installation\node_modules.npminstall_svg2react-loader@1.0.3@svg2react-loader\index.js:18:9 at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! testSvg@1.0.0 start: nowa server npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the testSvg@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

gbk commented 5 years ago

默认支持 svg 的,使用上有什么问题么? 另外 nowa v1 用的是 webpack v1.3,你的配置是 webpack v2 以上的写法,不会生效

icoreman commented 5 years ago

默认支持svg的,使用上有什么问题么?另外 nowa v1用的是webpack v1.3,你的配置是webpack v2以上的写法,不会生效

看到了,是react依赖的react-svg-loader。配置的截图是脚手架的。本来设置的版本是v2,但webpack版本实际是1.5,还是我本地是1,5?我待会确认下。 所以这个脚手架使用svg不需要配置什么嘛?直接就可以使用?我找了半天

icoreman commented 5 years ago

我用v2版本新建一个项目,引入svg。 import Icon from 'react-svg-loader!../../images/chance_new.svg'; 这种方法是不是错的?还是说我的svg图片有问题? 如果这种方式是错的,那么正确的方式是什么呢?请教下! 脚手架里面没有说明啊

gbk commented 5 years ago

import Icon from 'xxx.svg' 就可以了 详见文档 https://nowa-webpack.github.io/docs/tu_pian_he_svg_de_shi_yong.html

icoreman commented 5 years ago

import Icon from 'xxx.svg' 就可以了 详见文档 https://nowa-webpack.github.io/docs/tu_pian_he_svg_de_shi_yong.html

多谢多谢