マイペースなRailsおじさん

Ruby、Ruby on Rails、オブジェクト指向設計を主なテーマとして扱います。だんだん大きくなっていくRuby on Rails製プロダクトのメンテナンス性を損なわない方法を考えたり考えなかったりしている人のブログです。

Angularプロジェクトをコピーしたらビルドできなかった

Angular CLIで作ったプロジェクトをコピーしたらビルドがコケました。

隠しファイル(ドットファイル)をコピーし損ねてたただけでした(汗)

 

> cp -r angular-app/* .

> ng build
Cannot read property 'config' of null
TypeError: Cannot read property 'config' of null
at Class.run (/home/tanaka/scala/play/play-scala-seed/src/node_modules/@angular/cli/tasks/build.js:15:56)
at Class.run (/home/tanaka/scala/play/play-scala-seed/src/node_modules/@angular/cli/commands/build.js:216:26)
at resolve (/home/tanaka/scala/play/play-scala-seed/src/node_modules/@angular/cli/ember-cli/lib/models/command.js:261:20)
at new Promise (<anonymous>)
at Class.validateAndRun (/home/tanaka/scala/play/play-scala-seed/src/node_modules/@angular/cli/ember-cli/lib/models/command.js:240:12)
at Promise.resolve.then.then (/home/tanaka/scala/play/play-scala-seed/src/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:140:24)
at <anonymous>

エラーメッセージで検索すると、Angular-CLIのissueにヒントがありました。

github.com

ardiadrianadri commented on Feb 17 I know why it is happening but I don't know how to solved. The problem is that the transpiled JS code remove the "." at the beginning of the string ".angular-cli.json", so angular-cli cannot find the configuration file because it is looking for a file that doesn't exist. Let me show you:

This is the content of packages/@angular/cli/models/config.ts:

(...) import * as chalk from 'chalk'; import * as fs from 'fs'; import * as path from 'path';

export const CLI_CONFIG_FILE_NAME = '.angular-cli.json'; const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json'; (..)

以前はトランスパイルするとファイル名の頭のドットが取れてしまうバグがあったようですね。 リンク先の問題とは違いますが、私の環境では".angular-cli.json"がコピーできていなかったのでコケていました。

cp -r ~/myapp/.angular-cli.json ~/myapp/.editorconfig .

 これでビルドが成功するようになりました。

ワイルドカードで指定しても、ドットファイルは拾ってくれないんですね。 今まで意識していませんでした。