Issue with Webpack: Unable to load CSS files that contain url() imports

After spending an hour trying to solve the problem, I am still clueless.

I've been using Webpack to build my Angular 2 app and I'm attempting to import CSS files from PrimeUI. However, during the build process, I encountered this error message:

ERROR in ./~/primeui/themes/omega/theme.css
Module build failed: /home/mc128k/node/angular2-webpack-starter/node_modules/primeui/themes/omega/fonts/roboto-v15-latin-regular.eot:1
(function (exports, require, module, __filename, __dirname) { c?

SyntaxError: Unexpected token ILLEGAL
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:513:28)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/mc128k/node/angular2-webpack-starter/node_modules/primeui/themes/omega/theme.css:6:156)
    at Module._compile (module.js:541:32)
    at Object.loaderContext.exec (/home/mc128k/node/angular2-webpack-starter/node_modules/webpack-core/lib/NormalModuleMixin.js:88:7)
    at Object.module.exports (/home/mc128k/node/angular2-webpack-starter/node_modules/to-string-loader/src/to-string.js:6:54)
 @ ./src/main.browser.ts 2:0-41

This issue arises when the CSS is being parsed by the style loader specified in the webpack configuration:

{
    test: /\.css$/,
    loaders: ['to-string-loader', 'css-loader']
}

If I remove this snippet, it leads to a lot of errors. However, issues occur when the CSS imports items like this:

src: url('fonts/roboto-v15-latin-regular.eot');

The compilation fails because webpack attempts to parse the font file. This problem occurs with other file types as well, such as woff and gif images.

It seems like the other loaders are being ignored, even though they are properly configured (I have tried copying various snippets).

 {
    test: /\.(ttf|gif|svg)(\?[a-z0-9]+)?$/,
    loader: 'file-loader'
},
{
    test: /\.(eot)(\?[a-z0-9]+)?$/,
    loader: 'file-loader'  
}

At this point, I am lost. I have read through documentation, consulted other resources, but I am unable to understand why webpack does not recognize a loader when encountering the url() function in the CSS.

Any help would be greatly appreciated.

Answer №1

Are you familiar with the resolve-url feature in webpack? It's quite handy!

When it comes to handling CSS, here's my go-to loader configuration:

{
      test: /\.css$/,
      loaders: ['style','css?sourceMap!postcss!resolve-url']
    },

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a grid layout by designing boxes using CSS and HTML

I'm in the process of creating a homepage and I'd like it to resemble this design: (not the best quality, but the software I used was subpar (I miss mspaint)) Originally, I used buttons which made linking and customization easy, but I encounter ...

Retrieve the value of a property in a directive's isolated scope

Is there a way to access the isolated scope's property in the directive tag? Let's take a look at a simplified example: angular.module('app', []) .controller('myController', function() { var result_el = document ...

Customizing CSS for AGM Info Windows

After creating an agm-info-window with an image and a small text (tittle), here is the code: <agm-marker [latitude]="lat3" [longitude]="lng3" [iconUrl]="icon"> <agm-info-window [disableAutoPan]="true" [isOpen]="true"> <div route ...

Expanding/Collapsing Indicator Stays in Place as Content Expands

I'm encountering a problem with my expand/collapse code. I want the p class="heading" tag in the HTML (which is responsible for toggling my expand/collapse box) to move down along with the expanding content. At the moment, the content expands and appe ...

Tips for locating a webpage element with Selenium?

click here for image driver=webdriver.Chrome() driver.get("https://compass.tinkoff.ru/") driver.maximize_window() driver.implicitly_wait(20) elem = driver.find_element(By.XPATH, '//button[text()="Open Full Map"]').click() tim ...

Tips on executing an ajax script when the page is reloaded

Is there a way to trigger the ajax script upon refreshing the page? I've encountered an issue where the ajax script fails to run as intended. Below is the script in question: $(window).bind("load", function() { var data = {}; data.emai ...

Exploring AngularJS: Directives not refreshing HTML upon promise resolution

Currently, I am in the process of writing some basic unit tests for my AngularJS application. One particular issue I am facing involves the bindings on the user interface that rely on a scope variable within my directive. This variable is populated upon th ...

Why does my dialog box only open the first time and not the second time?

I have created my own custom dialog box using jQuery and it seems to be working fine initially. However, after closing it once, when I try to open it again nothing appears. Can anyone help me identify what's causing this issue? Below is the source co ...

Interrupt the current with an external factor

I am working with a flexbox layout that currently looks like this: https://i.stack.imgur.com/ULHEk.jpg My main question now is whether there is a way to disrupt the flow externally from the flexbox, so that the blocked element can move to the next positi ...

Styling text using SVG in HTML

I'm trying to underline a text element in SVG using the text-decoration attribute, but I'm running into an issue with the color of the line not changing. Here is the code snippet I am working with: <svg id="svg" viewBox="0 0 300 ...

Customize stroke widths for each individual SVG item

I'm facing an issue with applying consistent stroke width to my CSS on a webpage. Here is the code snippet I am using: path { fill: none; stroke-width: 10pt; stroke: red; } Despite this, the rendering appears differently on certain SVGs. You c ...

Seamless connection through Shopify's Buy Button

I have created a website using HTML5 and I am trying to create a direct link to a product checkout page without all the additional formatting and features that come with BuyButton. Shopify has provided me with this code: <div id='product-component ...

Retrieve the Query String Information from a Link and Generate a New Link in Another List

I am looking to extract information from a link in #list and then use that information to create a new link in #list3. The link I have is http://jsfiddle.net/4y5V6/24/. Is there a way to set it up so that when a link is clicked, it automatically gets added ...

Using Jquery & HTML5 for Seamless Transition between Portrait and Landscape Modes

I am working on making my HTML page more user-friendly for tablets. One issue I'm facing is that when the tablet's orientation changes, the menu doesn't hide correctly if the width is less than the height. Here is the code snippet I have so ...

Utilizing ng-class in AngularJS based on the specific html elements

I am displaying each item from my array as an HTML paragraph using the ng-repeat directive. <p ng-repeat="item in queries track by $index">{{ item }}</p> The output looks like this: ------------ title 1 -------------- content 1 ------------ ...

Guide on utilizing protractor to confirm equality of two spans in varying positions?

<span ng-bind="locations.selectedCount" class="ng-binding">1005</span> <span ng-bind="locations.selectedCount" class="ng-binding">1005</span> What method can I use in Protractor to verify that the values of these two spans are ide ...

I am facing an issue where HTML is not loading images or some parts of my CSS in PHP

I've been working on connecting my website to a MySQL database using PHP. Initially, I thought I could keep the HTML and CSS the same, but after adding everything, the images on the website stopped showing up as they did before. The fonts and other el ...

Increasing box width in Django

I'm currently working on a website using Django all-auth for authentication. Everything is functioning perfectly, but I'm wondering if there's a way to increase the size of the username and password input boxes using HTML. Below is the code ...

Issue with system font weight not being respected in Chrome on Android

Looking for a font challenge? We've discovered that the Roboto font has a slim version that can be specified in CSS using font-weight: lighter or a weight value below 400. By using the rule font-weight: 200; font-family: Roboto;, we were able to get ...

Can you explain the meaning of 1__qem?

While looking at the default styles applied to HTML elements for Google Chrome, I came across this information on this page: p { display: block; -webkit-margin-before: 1__qem; -webkit-margin-after: 1__qem; -webkit-margin-start: 0; -web ...