LoginSignup
3
1

More than 5 years have passed since last update.

Angular CLI のバージョンを 1.7.3 から 6.0.1 にあげるときにつまずいた 3 点

Posted at

バージョンアップ

  • Angular CLI で作成したプロジェクトの Angular CLI をバージョンアップした
  • 手順は こちら をトレースした

バージョンアップ & マイグレーションコマンド

$ cd target-project/
$ yarn add --dev @angular/cli@^6.0.1
$ ng update @angular/cli --migrate-only --from=1.7.3

発生した問題

1. ビルドが通らない

  • yarn build を実行
$ yarn build
chunk {0} runtime.6afe30102d8fe7337431.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.e2ee1f7e974858d37595.css (styles) 45.3 kB [initial] [rendered]
chunk {2} polyfills.3a2cc09f9515a07bf722.js (polyfills) 59.1 kB [initial] [rendered]
chunk {3} main.555dba2cd512935e98e5.js (main) 490 kB [initial] [rendered]
Error: Expected to find an ngsw-config.json configuration file in the /Users/kasaharu/target-project folder. Either provide one or disable Service Worker in your angular.json configuration file.
Error: Error: Expected to find an ngsw-config.json configuration file in the /Users/kasaharu/target-project folder. Either provide one or disable Service Worker in your angular.json configuration file.
  • どうやら Service Worker の config ファイルが見つからなくなったらしい
  • 同じ悩み を発見
  • 下記の変更を入れることで解決
diff --git a/angular.json b/angular.json
index be4dab5..04bf825 100644
--- a/angular.json
+++ b/angular.json
@@ -42,7 +42,7 @@
               "vendorChunk": false,
               "buildOptimizer": true,
               "serviceWorker": true,
-              "ngswConfigPath": "/src/ngsw-config.json",
+              "ngswConfigPath": "src/ngsw-config.json",
               "fileReplacements": [
                 {
                   "replace": "src/environments/environment.ts",

2. テストが失敗する

  • src/assets/styles/_mixin.scss を用意している
  • stylePreprocessorOptions オプションを使って "includePaths":["src/assets/styles"] を指定している
$ yarn test
ERROR in ./src/app/app.component.scss
Module build failed:
@import 'mixin';
^
      File to import not found or unreadable: mixin.
      in /Users/kasaharu/target-project/src/app/app.component.scss (line 1, column 1)
 @ ./src/app/app.component.ts 18:21-52
 @ ./src/app/app.component.spec.ts
 @ ./src sync \.spec\.ts$
 @ ./src/test.ts
  • なぜか _mixin.scss の場所がわからなくなっている…
  • やむおえず、相対パスでファイルを import することで解決

3. テストの 1 回実行ができない

  • --single-run オプションがない
$ yarn test --single-run
Unknown option: '--singleRun'

:eyes:
- Wiki を見ると --watch=false オプションだけになったらしい…ので --watch=false に変更

最後に

  • yarn start --open で無事起動を確認

参考リンク

3
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
3
1