I'd like to load SVG files using svgo-loader in Webpack, but I get the following error:
ERROR in ./~/css-loader?modules&localIdentName=[name][local][hash:base64:5]!./~/autoprefixer-loader!./~/less-loader!./demo/src/components/App/components/Header/Header.less Module not found: Error: Cannot resolve module 'logo.svg' in /Users/mishamoroshko/react-autosuggest/demo/src/components/App/components/Header @ ./~/css-loader?modules&localIdentName=[name][local][hash:base64:5]!./~/autoprefixer-loader!./~/less-loader!./demo/src/components/App/components/Header/Header.less 6:199-218
ERROR in ./demo/src/components/App/components/Header/Header.less Module build failed: ModuleNotFoundError: Module not found: Error: Cannot resolve module 'logo.svg' in /Users/mishamoroshko/react-autosuggest/demo/src/components/App/components/Header
Here is the relevant code bits:
Webpack config
module: {
loaders: [
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style', 'css?modules&localIdentName=[name]__[local]___[hash:base64:5]!autoprefixer!less'),
exclude: /node_modules/
},
{
test: /\.svg$/,
loader: 'url?limit=8192!svgo'
},
...
]
}
package.json
"svgo": "^0.6.1",
"svgo-loader": "^1.1.0",
"url-loader": "^0.5.7",
...
Header.less
.logo {
background-image: url(./logo.svg);
}
logo.svg
and Header.less
are located in the same directory.
What am I missing here?
To reproduce:
1. git clone [email protected]:moroshko/react-autosuggest.git
2. cd react-autosuggest
3. git checkout a5f1a99
4. npm install
5. npm start
This css-loader
issue seems related.
As a workaround, changing:
background-image: url(./logo.svg);
to:
background-image: url(../parent-folder/logo.svg);
solves the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With