Skip to content

[AssetMapper] @import directive does not work in css #60729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lyrixx opened this issue Jun 6, 2025 · 1 comment
Open

[AssetMapper] @import directive does not work in css #60729

lyrixx opened this issue Jun 6, 2025 · 1 comment

Comments

@lyrixx
Copy link
Member

lyrixx commented Jun 6, 2025

Symfony version(s) affected

7.3.0

Description

In my app.css, I put

@import './test.css';

and in test.css:

body {
    background-color: red;
}

And the background is still white

=> My browser try to load https://127.0.0.1:8000/assets/styles/test.css, but faces a 404.

I'm using symfony-cli, but it's the same with caddy


Note

I have another issue this relative URL, but I cannot reproduce it because of this bug.

How to reproduce

See this repo

@PhilETaylor
Copy link
Contributor

PhilETaylor commented Jun 7, 2025

Duplicate of closed and unactioned #54024

This article gives you a quick fix, I have tested it in your reproducer and it worked there.

the key is to wrap in url()

@import url('./test.css');

Also noted in your reproducer that your import was not at the start of the file

The @import CSS at-rule is used to import style rules from other valid stylesheets. An @import rule must be defined at the top of the stylesheet, before any other at-rule (except @charset and @layer) and style declarations, or it will be ignored.

Image

Looks like

is designed to look for @import url() syntax... with the regex https://regex101.com/r/BOJ3vG/1 and thats why it works when there is a @import url() syntax but not when the url function is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants