Skip to content

Angular build fails if external library imports assets in CSS files #31018

Closed as not planned

Description

@maxpatiiuk

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

If user imports a CSS file that includes an asset url(), such asset is resolved correctly.

But, if such CSS file is imported by an external library, the asset is resolved automatically only in serve mode.

During build, the asset is not resolved:

Application bundle generation failed. [2.091 seconds]

✘ [ERROR] No loader is configured for ".woff2" files: ../node_modules/external-library/NotoSans.woff2

    ../node_modules/external-library/auto-imported.css:3:11:
      3 │   src: url("./NotoSans.woff2") format("woff2");

For build, the user needs to manually configure the ESBuild loader for each
asset type:

  "loader": {
    ".woff2": "file"
  },

Minimal Reproduction

  1. Clone this repo

    git clone https://github.com/maxpatiiuk/angular-no-external-asset-loader
    cd angular-no-external-asset-loader
  2. Install dependencies

    # To keep reproduction size minimal, I hardcoded a minimal root-level node_modules
    # So, install Angular dependencies only in the app folder:
    cd app
    npm install
  3. Build the app

    npx ng build

    See that there is no build error for the manually-imported.css file, but there is a build error for auto-imported.css.

  4. Start the development server in the app folder

    npx ng serve

    See that during serve, the font is loaded correctly from both css files without errors.

See /node_modules/external-library/ for an example external library with a CSS file.

Exception or Error


Your Environment

Angular CLI: 20.2.0
Node: 22.16.0
Package Manager: npm 10.9.2
OS: darwin arm64
    

Angular: 20.2.1
... compiler-cli, core, platform-browser

Package                      Version
------------------------------------
@angular-devkit/architect    0.2002.0
@angular-devkit/core         20.2.0
@angular-devkit/schematics   20.2.0
@angular/build               20.2.0
@angular/cli                 20.2.0
@schematics/angular          20.2.0
rxjs                         7.8.2
typescript                   5.9.2

Anything else relevant?

From my understanding, this is the ESBuild plugin Angular provides for resolving assets in CSS files:

/**
* Creates an esbuild {@link Plugin} that loads all CSS url token references using the
* built-in esbuild `file` loader. A plugin is used to allow for all file extensions
* and types to be supported without needing to manually specify all extensions
* within the build configuration.
*
* @returns An esbuild {@link Plugin} instance.
*/
export function createCssResourcePlugin(cache?: LoadResultCache): Plugin {

I am not sure why it is not applied to CSS files imported from external libraries.

Activity

  1. maxpatiiuk commented on Aug 22, 2025

    @maxpatiiuk
    Author

    Use case:

    • My design system library includes a custom font. I wish to auto-load the CSS file and the font for my consumers to simplify the "Get started" instructions for my library.

    This works in most bundlers, but not in angular-cli.

  2. alan-agius4 commented on Aug 22, 2025

    @alan-agius4
    Collaborator

    You need to configure a loader, since the CSS you are importing is being directly in JS which forces another pipeline.

    See: https://angular.dev/tools/cli/build-system-migration#file-extension-loader-customization

  3. angular-automatic-lock-bot commented on Sep 22, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  4. locked and limited conversation to collaborators on Sep 22, 2025
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions