2

I'm trying to use the semantic-ui-less package, but whenever I try to import one of the .less files, I get an error saying that ../../theme.config can't be found. Of course, I have a theme.config, but it can't find it.

The .less file that's importing theme.config is located in node_modules/semantic-ui-less/src/definitions/modules/checkbox.less. With a relative path of ../.., I would expect it to want themes.config to be in node_modules/semantic-ui-less/src, but obviously I can't put my own theme.config inside of an installed node module directory - so where can I locate it so that less will be able to find it? Or is there some configuration I can pass to less-loader that will tell it how to find it?

2 Answers 2

3

You can directly point webpack to your theme.config file with resolve.alias option:

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

And of course you need a loader for .config files.

Sign up to request clarification or add additional context in comments.

5 Comments

Hmm, I tried this and it's not working for me, I still get: Cannot resolve 'file' or 'directory' ../../theme.config in /home/talin/Projects/web/react-semantic-demo/node_modules/semantic-ui-less/definitions/modules Here's what I added to the webpack config: resolve: { alias: [ { '../../theme.config': path.resolve(ROOT_PATH, 'theme.config') } ] },
Also, I think there's an error in your example, according to the webpack docs alias takes a map, not an array - however, I tried it both ways and no effect.
You're right, its must be object. Try set key to theme.config
I've done some more experiments and looked at the code to less-loader. As far as I can determine, @import statements from within .less files don't go through the webpack resolver. To test this, I added a NormalModuleReplacementPlugin with a callback that logs the requested path to the console, and I see my .less files in the output, but not the .config file.
Did you add theme.config to less loader test regexp? test: /(\.less|theme\.config)$/
0

I use the solution provided in Artem Butusov's tutorial.

It solves the problem by running a postinstall script that fixes the wrong references in the semantic-ui-less package by overwriting the theme.config in node_modules with the one you provide.

It also fixes the wrong font paths in the themes.

(I came across this solution in an issue of semantic-ui-less when I was trying to solve this same problem.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.