Skip to content
This repository was archived by the owner on Aug 28, 2026. It is now read-only.
This repository was archived by the owner on Aug 28, 2026. It is now read-only.

Error can't find module when using less-loader and "module" options #74

Closed

Description

@zxcabs

Hello,
when i use "background: url(./icon.png)" in my less file i got error Module not found: Error: Cannot resolve module 'icon.png'.

Here part of webpack.config.js file

module: {
            loaders: [
                {
                    test: /\.less$/,
                    loader: ExtractTextPlugin.extract('style', 'css?module&localIdentName=[hash:base64:5]!postcss!less')
                },
                {
                    test: /\.(jpg|png)$/,
                    loader: 'url-loader?limit=100000'
                },
                {
                    test: /\.svg$/,
                    loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
                }
            ]
},

If remove module options or less-loader all works well.

Activity

  1. nkbt commented on Jun 9, 2015

    @nkbt

    @zxcabs are you using your png file in a mixin or something (not actual less file you require, but some other file somehow imported less-way)?

  2. zxcabs commented on Jun 10, 2015

    @zxcabs
    Author

    @nkbt No, it's simple less file

    .root {
      width: 29px;
      height: 29px;
      background: url('./icon.png');
      cursor: pointer;
    }
    
  3. nkbt commented on Jun 10, 2015

    @nkbt

    That is hard to tell, could be even some typo... If you could make a simple repo to reproduce the issue

  4. markdalgleish commented on Jun 10, 2015

    @markdalgleish
    Contributor

    I'm actually having the same issue trying to convert my current project to CSS Modules.

  5. nkbt commented on Jun 10, 2015

    @nkbt

    That is interesting. When I migrated our sprockets build with sass and all that kind of stuff - I had almost no issues. The only issue I had was - not correctly resolved path inside imported files and different mixins. But in general everything worked like a charm.

  6. nkbt commented on Jun 10, 2015

    @nkbt

    non-module mode

    loaderUtils.urlToRequest(url, root)

    returns url("+require("./cat.png")+")

    module mode

    require(" + loaderUtils.stringifyRequest(this, urlRequest) + ")

    gives url("+require("cat.png")+")

  7. zxcabs commented on Jun 10, 2015

    @zxcabs
    Author

    can anybody fix it? 😺

  8. nkbt commented on Jun 10, 2015

    @nkbt

    @zxcabs I kind of debugged all the chain and it is quite clear where exactly the issue, but that code was written on purpose...

    When I changed:

            if(!moduleMode) urlRequest = loaderUtils.urlToRequest(url, root);
            return "\"+require(" + loaderUtils.stringifyRequest(this, urlRequest) + ")+\"";

    to

            urlRequest = loaderUtils.urlToRequest(url, root);
            return "\"+require(" + loaderUtils.stringifyRequest(this, urlRequest) + ")+\"";

    Everything works fine.

  9. nkbt commented on Jun 10, 2015

    @nkbt

    @zxcabs @markdalgleish lol, you know what worked?

    20150610-231147

    No changes to loader at all.

  10. zxcabs commented on Jun 10, 2015

    @zxcabs
    Author

    oh 😄

  11. moroshko commented on Dec 27, 2015

    @moroshko

    Any update on this?

  12. markdalgleish commented on Jan 7, 2016

    @markdalgleish
    Contributor

    @moroshko we're still waiting to hear back on this issue in Less: less/less.js#2615

  13. safhac commented on Mar 24, 2016

    @safhac

    Not sure if this still an issue?, but this could be cause your package json has less in devdeps have you tried less-loader instead of less?

  14. 39 remaining items

  15. bradennapier commented on Jun 16, 2017

    @bradennapier

    hmm this seems to be an issue when just using postcss-loader as well.

  16. artialex commented on Jul 14, 2017

    @artialex

    adding resolve-url-loader fixes this for me
    ...!resolve-url!less...

  17. alexander-akait commented on Jul 14, 2017

    @alexander-akait
    Member

    @mnpenner @bradennapier can your provide minimum reproducible test repo?

  18. mnpenner commented on Jul 14, 2017

    @mnpenner

    Erm... I can't reproduce this is a new project. Here's what I tried [dead]. Will post again if I figure out to cause, unless maybe it was fixed recently.

  19. alexander-akait commented on Jul 14, 2017

    @alexander-akait
    Member

    For me, bug not related to css-loader. Seems more related to less/sass/etc/-loader.

  20. smashercosmo commented on Aug 29, 2017

    @smashercosmo

    This is what worked for me. Add to webpack config the following lines

    resolve: {
      modules: ['./', 'node_modules'],
    }
    
  21. ishenli commented on Jan 28, 2018

    @ishenli

    @smashercosmo I can not understand why it works。。It is surprise

  22. Spaxe commented on Apr 9, 2018

    @Spaxe

    Just traced my postcss-loader issue all the way here! Wow. Please fix. :)

  23. viT-1 commented on Jan 26, 2024

    @viT-1

    Still a bug with scss files and sass-loader (v8.0.2):
    css-loader (v6.9.1)

    Error: Cannot find module '/img/ajax-loader.gif'
    "resolve" / "modules" setting is not helped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions