error TS6231: Could not resolve the path '' with the extensions: '.ts', '.tsx', '.d.ts'

Viewed 10862

I'm working on firebase functions with typescript and this error appears in the console while running 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.

I have no idea where this might be arising from. I haven't changed anything since the last time this was working.

Any solutions?

9 Answers

I got this error when I used tsc init instead of tsc --init

Try to compile the project indicating the path of tsconfig.json (configuration file) or the directory where it is. Using --project.

tsc --project tsconfig.json

or

tsc --project ./

Here in this link tsc CLI Options you can find more options to compile your project.

Try tsc -watch, it fixed the issue for me

I was seeing this same error and it was obfuscating the real error under the covers.

Try compiling your typescript in one step, and then running the entry file as the second step. So essentially, not in watch mode.


FWIW, the error that was actually occurring for me was a failure of the code to read my environment variables. I traced it to an update from dotenv that broke the ability for NODE_ENV to be properly set (on a Windows machine) in my startup script.

from my experience, when you create a new tsconfig.json, there is like

,
  "files": [
    "\\",
    "\\"
  ]

in the bottom. so I just removed it, and that's solve my problem.

Try to remove "files" in the bottom of the archive. It worked for me.

Compile with:

tsc

And not with:

tsc . // remove the dot

So update package.json to:

"script: {
   "build": "rm -rf build && tsc", // delete build folder then complile
}

change the name of your file from .tsc to .ts and it will work :)

Related