Typescriptのプロジェクト始めようと思って、npm run tsc --init
でハマった
解決策がほかの時にも気を付けるべき内容だったので、残しておく
起こったエラー
typescriptをインストール
npm install typescript
package.json
にtscを登録
package.json
"scripts": {
"tsc": "tsc"
},
tsconfig.jsonを作成
npm run tsc --init
あれ?
実行結果
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@1.0.0 tsc: `tsc`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@1.0.0 tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\XXXX\AppData\Roaming\npm-cache\_logs\2020-05-22T18_01_55_736Z-debug.log
解決策
解決策はこちらにありました。
npm run (npm run-script) コマンドで実行するスクリプトに引数を渡す。2017
こう書かないといけないんですね。
npm run tsc -- --init
実行結果
message TS6071: Successfully created a tsconfig.json file.
うまくできました。
今までもnpm run command --option
でできてたと思ってたけど、運よく?運悪く?そういう場面に出会ってこなかっただけだったっぽい