-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
@import invalidates @charset declaration #1212
Comments
Do not use |
It would be nice to have this fixed. Relying on returning the correct http headers is painful when hosting a static app. |
We can't change your headers |
As a workaround one could use a plugin such as https://github.com/cqqccqc/webpack-utf8-bom to prepend a UTF-8 BOM to the generated files. |
Without webpack you will faced with the same issue, no problems on webpack side, modify <!DOCTYPE html>
<html>
<head>
<title>css-loader @charset error</title>
<script defer src="./index.js"></script>
<link href="./style-css-loader-only.css" rel="stylesheet">
</head>
<body>
<p class="greet">Markus</p>
</body>
</html> How to fix? Just add <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>css-loader @charset error</title>
<script defer src="./index.js"></script>
<link href="./style-css-loader-only.css" rel="stylesheet">
</head>
<body>
<p class="greet">Markus</p>
</body>
</html> |
Yes! If you control the HTML you can set charset to UTF-8. If you control the server you can set the charset in the Content-Type HTTP header. However, I ran into this issue when I tried to open a print popup in Safari. I had no control over the server, so I couldn't set any HTTP headers. On top of that, the I added the print popup to my repository. The CSS is served with an empty Content-Type header and the document that is opened in a new window contains The problem is that in some (rare) cases I need to be able to specify the charset of the file in the CSS. |
Exactly, sometimes I do not have the ability to control the HTML or headers, and I must rely on this feature of CSS which is currently not usable. Right now this plugin is resulting in CSS which is technically broken -- the charset tag cannot be placed in the middle of a file. Browsers are forgiving about this, but they will not parse the charset tag. Changing the HTML may be a solution for some people, but it does not fix the fact that the charset tag is in the middle of the file which is the primary problem here. |
Converting from one charset to another is out of scope, you can write
Can you provide link/screenshot where tag in the middle, I can't reproduce using repo above |
Oh, I see |
The same problem |
…irst rule in the file warning esbuild will issue a warning when `@charset` is in the middle of the file. This is caused by css-loader will concats the file and doesn't hoist `@charset`, (webpack-contrib/css-loader#1212). While, esbuild will issue a warning regarding the above, it will hoist to the very top. In many cases, this warning is not actionable by the users as the `@charset` would be likely specified in 3rd party libs. Closes #22097 (cherry picked from commit b3e5888)
…irst rule in the file warning esbuild will issue a warning when `@charset` is in the middle of the file. This is caused by css-loader will concats the file and doesn't hoist `@charset`, (webpack-contrib/css-loader#1212). While, esbuild will issue a warning regarding the above, it will hoist to the very top. In many cases, this warning is not actionable by the users as the `@charset` would be likely specified in 3rd party libs. Closes #22097
I have the same problem |
Any news on that? |
Have same issue when trying to add bundled bootstrap css, so there's no way i can just remove it from my css, because it's not my css |
Are there plans to address this? |
The only possible solution is removing |
But removing is not safe, because if you have characters which are more them ascii they will be broken, but now they are broken too 😄 |
For anyone else trying to deal with this I made it go away by adding charset: false to my sass options in webpack.config.js
|
Expected Behavior
The
@charset
declaration at the top of the generated CSS file.Actual Behavior
The
@charset
declaration is below the imported CSS. To determine fallback encoding the@charset
declaration must be at the start of the file (https://drafts.csswg.org/css-syntax-3/#determine-the-fallback-encoding).The sass-loader automatically prepends
@charset "UTF-8"
(or BOM if in compressed mode). This information seems to be lost after sending the CSS string through the css-loader.Code
Expected CSS:
Actual CSS:
How Do We Reproduce?
https://github.com/intemarkus/css-loader-charset-error
npm install
npm run build
Open dist/index.html in browser with file://.../css-loader-charset-error/dist/index.html
In some browsers (Chrome, IE, Edge) the CSS content isn't read as UTF-8.
The CSS file is generated with the MiniCssExtractPlugin, but the direct result of the css-loader is printed in the console window.
The text was updated successfully, but these errors were encountered: