0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

angular project作成時に`ng new .`したらschema validationでエラーになった

Last updated at Posted at 2025-12-22

Docker 環境で Angular アプリを新規作成しようとして、次のコマンドを実行しました。

$ docker compose run --rm app ng new . --directory .

すると、以下のようなエラーが発生して失敗しました。

Schematic input does not validate against the Schema

Data path "/name" must match pattern
"^(?:@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*/)?[a-zA-Z0-9-~][a-zA-Z0-9-._~]*$"

次のコマンドにすると正常に実行できました。

$ docker compose exec app ng new my-project --directory . 

ここで、my-projectは作りたいプロジェクトの名前です。

ng new の基本構文

Angular CLI の ng new は、次の形式で解釈されます。

ng new <name> [options]
  • <name> : 必須(プロジェクト名)
  • --directory : 作成先ディレクトリ(任意)

参考:Angular CLIの ng new リファレンス

ng new . --directory .

Angular CLI はこれを次のように解釈します。

項目
プロジェクト名 (name) .
配置先 (--directory) .

つまり、. がプロジェクト名として渡されている 状態です。

なぜ . はプロジェクト名として使えないのか?

Angular公式サイトの ng new リファレンス(Argumentsセクション)では、名前について明確に「The name of the new workspace and initial project.」と定義されており、暗黙的にワークスペース全体を識別する名前(npmパッケージ名としても通用する名前)を求めています。

Angular CLI のプロジェクト名は、内部的に npm package 名 として扱われます。
npm package 名には制約があり、. 単体は無効です。

そのため、Angular CLI の schema validation により、次のエラーが発生します。

Data path "/name" must match pattern ...

これは、

「プロジェクト名がルールに合っていない」

という意味です。

参考:npm package命名のガイドライン

結論

ng new .

-> Angular CLI 的に不正(仕様上できない)

代わりに、以下のように プロジェクト名と配置先を分けて指定する のが正解です。

ng new my-project --directory .

Docker 環境でも同様です。

docker compose exec app ng new my-project --directory .
Docker コマンド 意味
docker compose run --rm 一時コンテナで実行
docker compose exec 起動中コンテナで実行
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?