経緯
typescriptの勉強中、新しく「section2」ディレクトリを作って、
「section1」ディレクトリにあった下記のディレクトリ・ファイルを移動させた。
/dist
/src
package.json
tsconfig.json
移動後、npm install
を実行したら下記のエラーが出た。
ts.configの設定でなんか失敗したっぽい?
npm install
npm WARN deprecated tslint@6.1.3: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.
> section1@1.0.0 prepublish
> npm run build
> section1@1.0.0 build
> tsc
error TS18003: No inputs were found in config file 'C:typescript/section2/tsconfig.json'. Specified 'include' paths were '["src/**/*"]' and 'exclude' paths were '["node_modules","dist"]'.
Found 1 error.
npm ERR! code 2
npm ERR! path C:typescript/section2
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c npm run build
npm ERR! A complete log of this run can be found in:
原因
最初はnode_modulesフォルダが存在しないことで怒られているのかと思ったけど、
installして初めてできるものだから関係ない。
https://insider.10bace.com/2017/11/29/typescript-ts18003-error/ の記事を参考にすると、ディレクトリ内にtsファイルが存在しないとだめってことで怒られたらしい。
srcの中にダミーファイルとしてindex.tsを作り、作成されたnode_modules
とpackage-lock.json
を消してもう一度installを実行。
npm install
npm WARN deprecated tslint@6.1.3: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.
> section1@1.0.0 prepublish
> npm run build
> section1@1.0.0 build
> tsc
src/index.ts:1:2 - error TS1127: Invalid character.
1 {\rtf1}
Found 1 error in src/index.ts:1
npm ERR! code 2
npm ERR! path C:typescript/section2
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c npm run build
npm ERR! A complete log of this run can be found in:
なんで!?って思ってよく見たらindex.tsの記述がおかしいぞってちゃんと出ていた…
ファイルの中を空にして再実行したら下記のように成功!
エラーはちゃんと読まなきゃダメだね…
npm install
npm WARN deprecated tslint@6.1.3: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.
> section1@1.0.0 prepublish
> npm run build
> section1@1.0.0 build
> tsc
added 42 packages, and audited 43 packages in 4s
5 packages are looking for funding
run `npm fund` for details
2 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
今回の学び
・npm install失敗したときは、ダミーのtsファイルが入っているか確認する
・ダミーのtsファイルは空っぽにしておくか、正しいtsコードを入れておく
・エラーはちゃんと読む