Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack semantic-ui-less Module build failed

I have been following various tutorials on importing semantic-ui-less into a webpack project. However, whenever I have completed the different tutorials I am getting the same error:

Module build failed:

module.exports = __webpack_public_path__ + "static/media/reset.b0bc6c14.less";
             ^
Unrecognised input
      in /Users/benflowers/Projects/candidate/candidate-ui-cra/node_modules/semantic-ui-less/definitions/globals/reset.less (line 1, column 15)

Is this an issue with my webpack config - I have an ejected create-react-app webpack config with some additional loaders:

 {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            { loader: 'css-loader' },
            { loader: 'less-loader' }
          ]
        }),
        exclude: [/[\/\\]node_modules[\/\\]semantic-ui-less[\/\\]/]
      },

      // for semantic-ui-less files:
      {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            { loader: 'css-loader' },
            {
              loader: 'semantic-ui-less-module-loader',
              // you can also add specific options:
              options: { siteFolder: path.join(__dirname, 'src/site') }
            }
          ]
        }),
        include: [/[\/\\]node_modules[\/\\]semantic-ui-less[\/\\]/]
      },

      // loader for static assets
      {
        test: /\.(png|jpg|jpeg|gif|svg)$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10240,
            absolute: true,
            name: 'images/[path][name]-[hash:7].[ext]'
          }
        },
        include: [path.join(__dirname, 'src'), /[\/\\]node_modules[\/\\]semantic-ui-less[\/\\]/]
      }

as per https://github.com/gadyonysh/semantic-ui-less-module-loader

like image 473
Ben Flowers Avatar asked Apr 07 '26 14:04

Ben Flowers


2 Answers

I had the similar issue. I just added to webpack config

ALIAS

  resolve: {
      ...
        alias     : {
            '../../theme.config$': path.join( __dirname, '../src/assets/theme/theme.config' )
          }
    },

LESS LOADER

{
            test: /\.less$/,
            use : ExtractTextPlugin.extract( {
              fallback: [ {
                loader: 'style-loader',
              } ],
              use     : [ 'css-loader', 'resolve-url-loader', 'less-loader', 'postcss-loader' ]
            } )
          },

and exclude

{
                exclude: [
                    /\.(config|overrides|variables)$/,
                    /\.html$/,
                    /\.(js|jsx)$/,
                    /\.css$/,
                    /\.json$/,
                    /\.bmp$/,
                    /\.gif$/,
                    /\.jpe?g$/,
                    /\.png$/,
                    /\.scss$/,
                ],
                loader: require.resolve( 'file-loader' ),
                options: {
                    name: 'static/media/[name].[hash:8].[ext]',
                },
            },

please pay attention to line /.(config|overrides|variables)$/,

like image 120
Arthur Avatar answered Apr 09 '26 04:04

Arthur


Adding this to your less exclude should do the trick :

exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/, /\.(less|config|variables|overrides)$/],
like image 43
Trip Avatar answered Apr 09 '26 02:04

Trip