5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

cssで@charset "UTF-8"に関するエラー「at-rule or selector expected」

Posted at

初学者です。出会ったエラーを軽くアウトプットしていきます。

開発環境

PHP 7.3.9
MAMP 5.7
Mysql 5.7.26
Laravel 6.20.7

エラー内容

vsコード内にてpublic/scc/app.sccのステータスバーにある"問題"で__「at-rule or selector expected」__という表示がある。
viewには特に問題なく表示されている。

*ただし、過去に同様のエラーがあった際はviewで何らかのエラーが出ていたと記憶しています。
再現性がなくて申し訳ないです。

原因

単純に__@charset "UTF-8";__という文字コードが2行目でこのように定義されていたのが原因です。

app.css

@import url(https://fonts.googleapis.com/css?family=Nunito);@charset "UTF-8";

解決法

@charsetの文字コード定義は必ず1行目かつ@charsetの前には何も書いてはいけないので、

app.css
@charset "UTF-8";
@import url(https://fonts.googleapis.com/css?family=Nunito);

こうすれば解決します。

正直、何が原因で@charset "UTF-8";が2行目になってしまっているのか特定できてないですが、
laravel/uiパッケージをインストールした後、スカフォールドを生成。ターミナルでnpm installを実行してフロントエンド開発に必要な依存パッケージをインストールしてapp.cssが作成された段階ですでに@charset "UTF-8";が2行目になっているので適宜修正するしかないかと...

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?