@TaikiTkwkbysh (WAKA Engineer)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

【Typescript】コンパイエラー TS6231が解決できない。

解決したいこと

Typescriptを学習中のものです。
コンパイルエラーTS6231の原因がわからず困っております。

■発生している問題・エラー

error TS6231: Could not resolve the path '' with the extensions: 
'.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts'.
  The file is in the program because:
    Root file specified for compilation


Found 1 error.

■ディレクトリ構造

スクリーンショット 2022-09-04 19.05.11.png

■目的と実行手順

目的

section1_typesection2_compile内のsrc内にあるtsファイルをコンパイルしたい。
コンパイルする際にはtsconfig.jsonの設定を反映させたい。

実行手順

①TSファイル内に移動

②Tsファイル内で、tsc .を実行 → エラー発生

■package.json

{
  "name": "ts",
  "version": "1.0.0",
  "description": "learning-typescript",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "users",
  "license": "UNLICENSED",
  "devDependencies": {
    "@types/node": "^16",
    "typescript": "^4.7"
  }
}

includeとexcludeは無くても同様のエラーが発生致します。

■tsconfig.json

{
  "compilerOptions": {
    "target": "es2016"
    "module": "commonjs"
    "esModuleInterop": true
    "strict": true 
    "skipLibCheck": true
  },
  "include": ["**/*.ts"],
  "exclude": ["node_modules", "*.js", "*/dist", "*/index"]
}

各バージョン

項目 バージョン
typescript 4.7.4
npm 8.16.0
node v14.17.4

ご存じでしたらご教示の程、宜しくお願い致します。

0 likes

3Answer

tsc . ではなく tsc を実行してください。引数を渡す場合は1つ以上の ts または js ファイルでなくてはならず、 . は受け付けません。

1Like

一度のtscコマンドで、添付写真のような状態に出力させることは恐らく難しいですよね?

一度では無理です。

1Like

Comments

  1. @TaikiTkwkbysh

    Questioner

    @uasi様
    承知いたしました。
    度々ご教示頂き、誠にありがとうございます!

    今後ともご教示いただけますと幸いです。
    以上、宜しくお願い致します。

@uasi

この度はお忙しい中ご教示頂き、誠にありがとうございます。
ご教示いただいたようにtscで実行したところ、エラーも出ずコンパイルすることができました。

もう1点ご教示頂きたい事があるのですが、自分も作成中に少し無謀かなとは思ったのですが、
一度のtscコマンドで、添付写真のような状態に出力させることは恐らく難しいですよね?

スクリーンショット 2022-09-05 20.23.54.png

■解説
①TSディレクトリ内でtscコマンドを実行する。

②section1_typeとsection2_compile内のsrc内にあるtsファイルをコンパイルするが、
section1_type にあるstudy1.tsの出力結果は、section1_type内にあるdistディレクトリに、
section2_compileにあるcompile.tsの出力結果は、section2_compile内にあるdistディレクトリに出力する。

それぞれのファイルを指定して行えば可能かもしれませんが、それだとtsconfig.jsonの条件を無視することになりますし...。

度々恐れ入りますが、ご教示の程宜しくお願い致します。

0Like

Your answer might help someone💌