Semantic-UI-CSS: Unable to load semantic-ui-css with extract text plugin webpack
I’m trying to import semantic-ui-css via webpack into my script and i keep getting the error
Unexpected character '@' (11:0)
You may need an appropriate loader to handle this file type.
I am using the extract text plugin to separate my sass into a file of its own
// Import file in main file
import 'semantic-ui-css/semantic.min.css';
export default class MainContainer extends React.Component {
...
}
webpack config
// webpack.config.js
const webpack = require('webpack');
const path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
entry: {
main: __dirname + '/client/main-container.js',
vendors: [
'react',
'react-dom',
'redux',
'react-router',
'semantic-ui-react',
'axios',
'react-router-redux',
'react-redux-toastr',
'react-redux'
]
},
output: {
path: './client/build',
filename: 'bundle-[chunkhash].js',
},
stats: {},
module: {
loaders: [
{
test: /\.js/,
exclude: /node_modules/,
loader: 'babel',
include: __dirname + '/client',
resolve: {
extensions: ['', '.js', '.jsx'],
},
},
{
test: /\.scss/,
include: __dirname + '/client',
loader: ExtractTextPlugin.extract('style', 'css!sass')
},
{
test: /\.css/,
include: __dirname + '/client',
loader: ExtractTextPlugin.extract('style', 'css-loader')
}
],
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors-[chunkhash].js', Infinity),
new ExtractTextPlugin("[name]-[chunkhash].css"),
function() {
this.plugin("done", function(stats) {
require("fs").writeFileSync(
path.join(__dirname, "client", "build", "stats.json"),
JSON.stringify(stats.toJson().assetsByChunkName));
});
},
new CleanWebpackPlugin(['build'], {
verbose: true,
dry: false,
root: __dirname + '/client',
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV) || JSON.stringify('dev')
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin()
]
};
any help would be great.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 16
Adding
url-loader
to the config solves the issue for me:And you need to
npm i url-loader file-loader -S
I’ve consolidated all the recommendations into a single post that worked for me.
Ensure you have installed
yarn save --dev url-loader file-loader css-loader style-loader
Basic webpack config only relating to adding semantic-ui-css. I followed the guide from https://github.com/webpack-contrib/css-loader. You don’t need sass loaders given its already a minified css file.
Note:
include: /node_modules/
The errors are pretty standard, it means that webpack doesnt understand the file type and cant parse the contents. 99% its a missing or misconfigured loader. The full
semantic-ui
package actually works well with webpack, I’ll post a guide about setting it all up later.@chainlink you should post your webpack config for troubleshooting
Documentation is not clear on how to resolve this issue. I tried almost all the options from this thread but it still gives me this error.
Edit: somehow I missed that the thread is specifically about using the ExtractTextPlugin to load the CSS. I’ll leave this here for anybody anyway though as I ended up here when I faced a similar problem.
Webpack and all the other parts are still a bit of a magic box to me, so apologies for not having more insight – but here’s a setup that might work if the others haven’t.
I was able to resolve the issue @wildcookie007 was getting, and another error when resolving the .png country flag images in the library by using a combination of
css-loader
,style-loader
, andfile-loader
in the following way…In the root JS file of the project:
import 'semantic-ui-css/semantic.min.css'
Had the same issue with using semantic-ui-css module and finally realised that the problem was in excluding node_modules folder from working dirs of css loader. Just make shure that your config allows css-loader to handle node_modules/semantic-ui-css. Hope this will help anybody.
Was able to install semantic-ui-css by: create file styles.global.scss with
@import '~semantic-ui-css/semantic.css';
then import it in js filesimport './styles/styles.global.scss'
these are my loader { test: /.(ttf|eot|svg|woff|woff2)(?v=[0-9].[0-9].[0-9])?$/, use: [{ loader: ‘file-loader’ }] }, { test: /.(png|jpg|gif)$/, use: [{ loader: ‘file-loader’ }] }, { test: /.html$/, use: [ { loader: “html-loader” } ] }, { test: /.css$/, use: [{ loader: ‘style-loader’ }, { loader: ‘css-loader’ } ] }, { test: /.(sass|scss)$/, use: [ { loader: ‘style-loader’ }, { loader: ‘css-loader’ }, { loader: ‘sass-loader’ }, ] }
hope this is helpful. it seems to be working fine for now
Hello all, I have been struggling with the similar issue… not able to parse module, unexpected char ‘@’ BTW, which version of webpack is everybody using? I happen to use webpack^3.3.0, not sure if this can be a problem.
Here is my webpack code, and I don’t really know what I am doing after hours of searching the right solution. I’d really appreciate your insights…