0

When I try to import a .less from my React component I get the following error:

Module not found: '[object Object]' in /path/to/src

Here's a part of my webpack config that's taking care of css and less loading:

...
{
    test: /\.css$/,
    loader: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: [
        {
          loader: 'css-loader',
          options: {
            modules: true,
            importLoaders: true,
            localIdentName: '[name]__[local]___[hash:base64:5]'
          }
        },
        'postcss-loader'
      ]
    })
  },
  {
    test: /\.less$/,
    loader: ExtractTextPlugin.extract({
      fallback: 'style-loader',
      use: [
        {
          loader: 'css-loader',
          options: {
            modules: true,
            sourceMap: true,
            importLoaders: true,
            localIdentName: '[name]__[local]___[hash:base64:5]'
          }
        },
        'less-loader'
      ]
    })
  },
...

In my component, I'm importing the .less style file, like so:

import styles from './App.less'

I've tried reading related github issues and been debugging this for a while. Would love some help!

vijay
  • 324
  • 1
  • 4
  • 11
  • Have you tried `loader: 'less-loader'` instead of just `less-loader`? – Siya Mzam Nov 11 '17 at 07:27
  • do you mean in the object that tests for `test: /\.less$/` ? At the end using { loader: 'less-loader' }. That doesn't work either – vijay Nov 11 '17 at 07:29
  • Yes, the exact same setup you have just with `loader` before you specify the actual loader. – Siya Mzam Nov 11 '17 at 07:30
  • Also, `less-loader` compiles `.less` files to `.css` which I think are the files you are supposed to import as opposed to importing `.less` files themselves. – Siya Mzam Nov 11 '17 at 07:34
  • That's an excellent point, but I'm aware of applications that load `.less` files directly into the component. In the same way, components can also load `.scss` files and webpack will take care of parsing it behind the scenes – vijay Nov 11 '17 at 07:43
  • Alright, no problem. Did you try what I suggested? Did it work? – Siya Mzam Nov 11 '17 at 07:48
  • Yup I did try it, unfortunately it still throws the same error. Also tried using `.css`; that fails too – vijay Nov 11 '17 at 07:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/158752/discussion-between-fshock-and-vjrngn). – Siya Mzam Nov 11 '17 at 08:22

0 Answers0