8
2

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.

AngularJSで”ng serve"立ち上げ時のエラー解決

Posted at

エラー内容

Angular CLIでサーバーを立ち上げようとしたところ、
下記の様なエラーが出力され、日本語用の掲示板がなく、苦戦。

備忘録と日本語用の解決方法として記録する。

環境

  • Mac OS Catalina 10.15.7
  • zsh
  • Node.js 15.0.1
  • npm 7.0.3
  • Angular 10.0.14
  • Angular CLI 10.0.8

コード

立ち上げ

% ng serve

すると下記の様なエラーが出力された。

An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'
Require stack:
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/models/architect-command.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/commands/serve-impl.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/utilities/json-schema.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/models/command-runner.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/lib/cli/index.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/lib/init.js
- /Users/username/.nodebrew/node/v15.0.1/lib/node_modules/@angular/cli/bin/ng
See "/private/var/folders/mz/z5f4vq_n6vz50y0g7vt85v4r0000gn/T/ng-7crVaj/angular-errors.log" for further details.

エラーの解決方法がググって検察してみたものの
なかなか出てこず、うまくいかず下記のサイトにてようやく答えが見つかる。
参考:Cannot find module @angular-devkit/build-angular/package.json

% npm install --save-dev @angular-devkit/build-angular

と入力したら

added 1484 packages, and audited 1484 packages in 21s

4 high severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

と出力されたので、指示通り、

% npm audit fix --force

と入力。

改めて

% ng serve

を入力したところ、

Your global Angular CLI version (10.2.0) is greater than your local
version (10.0.8). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
Compiling @angular/core : es2015 as esm2015
Compiling @angular/animations : es2015 as esm2015
Compiling @angular/cdk/keycodes : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/cdk/observers : es2015 as esm2015
Compiling @angular/animations/browser : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/cdk/platform : es2015 as esm2015
Compiling @angular/cdk/bidi : es2015 as esm2015
Compiling @angular/forms : es2015 as esm2015
Compiling @angular/router : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @angular/platform-browser/animations : es2015 as esm2015
Compiling @angular/cdk/a11y : es2015 as esm2015
Compiling @angular/material/core : es2015 as esm2015
Compiling @angular/material/button : es2015 as esm2015
Compiling @angular/material/toolbar : es2015 as esm2015

chunk {main} main.js, main.js.map (main) 19.7 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 168 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.2 MB [initial] [rendered]
Date: 2020-10-25T02:26:54.690Z - Hash: 3772bde64fed4e4284bc - Time: 5678ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
: Compiled successfully.

無事立ち上がった!

ps エラー解決には英語も欠かせないな

8
2
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
8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?