Skip to content

import with absolute paths #93

Closed
m1guelpf/miguelpiedrafita.com
#14

Description

@wclr

I have imports in less files:

@import "/styles/imports/mixins";

Got the error:

ERROR in ./client/~/css-loader!./client/~/less-loader?{lessOptions}
Module build failed: Can't resolve **'.//styles/imports/mixins.less'**

in lessOptions I passed {paths: [absoulte path to directory where /styles dir is located]}

Activity

  1. nicolas-goudry commented on Jun 30, 2016

    @nicolas-goudry

    I'm also stuck with this issue, any workaround / config to ship ?

    Actually I handle that by doing @import "../../../styles/settings/all"; but it's clearly not the right way to do this…

    In my webpack.config.js:

    webpackConfig.module.loaders.push({
      test: /\.less/,
      include: cssModulesRegex,
      loaders: [
        'style',
        cssModulesLoader,
        'postcss',
        'less?sourceMap'
      ]
    })
    
    /* … */
    
    webpackConfig.lessLoader = {
      includePaths: paths.client('styles')
    }

    Also, imports from node_modules doesn't work: @import "~normalize.css/normalize.css"; but if I use @import "normalize.css/normalize.css";, it works…

  2. vangheem commented on Nov 17, 2016

    @vangheem

    Any reason why this was closed? This is still an issue where absolute paths do not get resolved correctly. This includes absolute urls that are generated with variables like @import "@{pathVariable}/foobar";

  3. n1ru4l commented on May 22, 2017

    @n1ru4l
    Contributor

    I can confirm this @vangheem

  4. alexander-akait commented on May 22, 2017

    @alexander-akait
    Member

    import using absolute paths can weird and incorrect behavior. Who can demonstrate use case and explain that only with absolute paths is it possible?

  5. n1ru4l commented on May 22, 2017

    @n1ru4l
    Contributor

    I have a use case. I want to load a .less file which includes variables for a theme.
    The users should be able to specify the path of the theme.

    Atm. absolute paths are prefixed with ./

    Example:

    const defaultTheme  =  `themes/variables/default.less`
    const themeDir = path.resolve(__dirname, `..`, defaultTheme) // /Users/my-user/Projects/private/muse-ui/themes/variables/default.less
    
    const loader = {
      loader: `less-loader`,
      options: {
        globalVars: {
          theme: `'${themeDir}'`
        }
      }
    }

    The webpack output is the following:

    Module build failed: Can't resolve './/Users/sum-user/Projects/private/muse-ui/themes/variables/default.less' in '/Users/sum-user/Projects/private/muse-ui/src/styles'
     @ /Users/sum-user/Projects/private/muse-ui/src/styles/import.less (line 1, column 0)
     near lines:
       
       @import "@{theme}";
    
    
  6. alexander-akait commented on May 22, 2017

    @alexander-akait
    Member

    @n1ru4l Can't resolve './/Users/sum-user/Projects/private/muse-ui/themes/variables/default.less' - seems something is wrong with path. Be good if your show full stack trace of error.

  7. n1ru4l commented on May 22, 2017

    @n1ru4l
    Contributor

    @evilebottnawi I know that something is wrong with the path. Because it should not get prefixed with ./... if you enter cat /Users/sum-user/Projects/private/muse-ui/themes/variables/default.less into the terminal the file contents are shown...

  8. alexander-akait commented on May 22, 2017

    @alexander-akait
    Member

    @n1ru4l I think I can look what's wrong in this week. Now overloaded 😞 Just ping me in friday, if no information here or will not be PR

  9. n1ru4l commented on May 22, 2017

    @n1ru4l
    Contributor
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