错误 TS6231:无法解析带有扩展名的路径 '':'.ts'、'.tsx'、'.d.ts'

Viv*_*vek 24 javascript function firebase typescript

我正在使用打字稿处理firebase函数并且在运行时控制台中出现此错误:tsc . -watch

[12:19:41 PM] Starting compilation in watch mode...

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

[12:19:45 PM] Found 1 error. Watching for file changes.
Run Code Online (Sandbox Code Playgroud)

我不知道这可能是从哪里产生的。自从上次工作以来我没有改变任何东西。

有什么解决办法吗?

Wil*_*iam 41

tsc init 当我使用而不是时 出现此错误tsc --init


Dav*_*ijr 15

尝试编译项目,指示 tsconfig.json(配置文件)的路径或其所在目录。使用--项目。

tsc --project tsconfig.json
Run Code Online (Sandbox Code Playgroud)

或者

tsc --project ./
Run Code Online (Sandbox Code Playgroud)

在此链接tsc CLI Options中,您可以找到更多选项来编译项目。


LEM*_*ANE 10

使用:

tsc
Run Code Online (Sandbox Code Playgroud)

并不是:

tsc . // remove the dot
Run Code Online (Sandbox Code Playgroud)

因此将 package.json 更新为:

"script: {
   "build": "rm -rf build && tsc", // delete build folder then complile
}
Run Code Online (Sandbox Code Playgroud)


小智 3

尝试一下tsc -watch,它解决了我的问题