1

I'm working on a Symfony project and using Asset Mapper for the first time. I'm having trouble importing CSS files into a main CSS file. Here’s the situation:

My admin.css file works fine when I add CSS directly to it.

However, when I try to use @import './components/admin/_stat_card.css' inside admin.css, it doesn’t work.

Context

The path seems correct (based on my project structure), but in the browser, I get the following error:

GET https://localhost/assets/styles/components/admin/_stat_card.css net::ERR_ABORTED 404 (Not Found)

Here’s the structure of my assets/ folder:

assets/
├── styles/
│   ├── admin.css
│   └── components/
│       └── admin/
│           └── _stat_card.css

Here is my config/packages/asset_mapper.yaml file:

framework:
    asset_mapper:
        # The paths to make available to the asset mapper.
        paths:
            - assets/
        missing_import_mode: strict

when@prod:
    framework:
        asset_mapper:
            missing_import_mode: warn

And this is how i use my admin.css in my admin layout template :

<link rel="stylesheet" href="{{ asset('styles/admin.css') }}">

What I’ve checked:

The _stat_card.css file exists in the correct location.

I used the command php bin/console asset-map to confirm that my files are properly mapped.

Despite all this, the error persists, and the imported file is not found.

Questions:

  • Did I miss something in my configuration?

  • Does Asset Mapper handle CSS imports (@import) as I expect?

1
  • 2
    There's a section in the docs that addresses this and talks about ways to debug this Commented Apr 14 at 13:53

1 Answer 1

1

I had the same misunderstanding. In you admin.css file, use url() to import :

@import url('./components/admin/_stat_card.css');

Should probably work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.