Roots Discourse

How to use files from /assets in scss

In my scss, I reference a file from the /assets folder like so:

.selector {
    background-image: url(../../images/svg/gears.svg);
}

Everything’s fine using yarn run start and yarn run build. However, when executing yarn run build:production the following error is thrown:

ERROR in ../~/css-loader?-sourceMap!../~/postcss-loader!../~/resolve-url-loader?-sourceMap!../~/sass-loader?-sourceMap!./styles/main.scss
    Module not found: Error: Can't resolve '../../images/svg/gears.svg' in '/Applications/MAMP/htdocs/openminds/wp-content/themes/hoang/assets/styles'
     @ ../~/css-loader?-sourceMap!../~/postcss-loader!../~/resolve-url-loader?-sourceMap!../~/sass-loader?-sourceMap!./styles/main.scss 6:194746-194783

How can I properly reference the assets folder so that it doesn’t break yarn build:production?

Use ../images, not ../../images

duh! forgot that it’s technically being referenced by main.scss, not the included file. Thanks @benword

Hi @benword
I’m actually using the correct syntax but I get error

Module build failed: Error: resolve-url-loader: CSS error
  predicate must return an absolute path or the result of calling next()

More details here:

Any idea? I’m spending hours and hours not finding solution :frowning:

1 Like