jhamlet / svg-react-loader

Webpack SVG to React Component Loader
MIT License
559 stars 82 forks source link

utf-8 bom issue #3

Closed ccorcos closed 9 years ago

ccorcos commented 9 years ago
ERROR in ./~/babel-loader!./~/svg-react-loader!./ui/images/affirm-logo.svg
Module build failed: Error: Non-whitespace before first tag.
Line: 0
Column: 1
Char: m
    at error (/Users/chetcorcos/code/styleguide/node_modules/svg-react-loader/node_modules/xml2js/node_modules/sax/lib/sax.js:652:8)
    at strictFail (/Users/chetcorcos/code/styleguide/node_modules/svg-react-loader/node_modules/xml2js/node_modules/sax/lib/sax.js:675:22)
    at Object.write (/Users/chetcorcos/code/styleguide/node_modules/svg-react-loader/node_modules/xml2js/node_modules/sax/lib/sax.js:955:11)
    at Parser.exports.Parser.Parser.parseString (/Users/chetcorcos/code/styleguide/node_modules/svg-react-loader/node_modules/xml2js/lib/xml2js.js:481:31)
    at Parser.parseString (/Users/chetcorcos/code/styleguide/node_modules/svg-react-loader/node_modules/xml2js/lib/xml2js.js:7:59)
    at Object.module.exports (/Users/chetcorcos/code/styleguide/node_modules/svg-react-loader/index.js:45:15)
 @ ./checkout/main.js 50:17-65
jhamlet commented 9 years ago

@ccorcos Can you supply that SVG for me to test against?

ccorcos commented 9 years ago

crap. I meant to close this. It was a problem with the way I was loading it. you need to prefix require("-!... when you're overriding other loaders...

jhamlet commented 9 years ago

Ahh.. Ok. cool.

mauron85 commented 8 years ago

@ccorcos I have same problem on OSX. How exactly did you override loader? I'm using it as in example:

const Icon = require('babel!svg-react!./settings.svg?name=Settings');

EDIT: The problem is in webpack ^2.1.0-beta.4 Version ^1.12.14 seems to be fine.

ccorcos commented 8 years ago
const Icon = require('-!babel!svg-react!./settings.svg?name=Settings');
mauron85 commented 8 years ago

Ok thanks. My problem at the end was that svg-reat-loader seems not to work with webpack 2.1.0-beta.4. Downgrade to 1.12.14 solved my problem.

hunthunthunt commented 8 years ago

The -! prefix worked for me also, for anyone looking for ES6/2015 syntax, try:

import MyIcom from '-!babel!svg-react!assets/images/fooIcon.svg?name=MyIcon';

gwagener commented 7 years ago

Nice. This allowed it to work for me in create-react-app-ts as I can't change the existing loaders.

zeeshanjan82 commented 7 years ago

@hunthunthunt I am getting the error: : The node API for babel has been moved to babel-core. when using the import command you have provided.

vikasrohit commented 7 years ago

Sorry to post on closed thread, posting my exp so that others can take help.

Not sure why(I am not expert webpack and its loaders), but for me prefixing with simple ! worked, -! was not working.

william-abboud commented 6 years ago

@vikasrohit Yeah totally right man. Just prefixing it with ! worked for me too.

I used the following path import import Icon from '!svg-react-loader!../assets/icons/menu.svg';

with the following config in webpack

{
    test: /\.svg$/,
    loader: 'svg-react-loader',
    query: {
        classIdPrefix: '[name]-[hash:8]__'
    }
}