Reputation: 401
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?
Upvotes: 29
Views: 39459
Reputation: 69
There are several solutions.
First. By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.
$ npx tsc
* Caution: Do not use dot in the first example
Second. By invoking tsc with no input files and a --project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file, or a path to a valid .json file containing the configurations.
$ npx tsc --project tsconfig.json
or
$ npx tsc --project .
Upvotes: 1
Reputation: 1
In package.json for Windows
"scripts": {
"start": "rimraf dist && tsc-watch --onSuccess \"npm run watch\"",
"watch": "nodemon \"src/app.ts\" --watch \"./src\""}
Upvotes: 0
Reputation: 1
remove "files": [""]
use "rootDir": "./src", "outDir": "./output"
keepall .ts files inside 'src' folder
Upvotes: 0
Reputation: 8818
Use:
tsc
And not:
tsc . // remove the dot
So update package.json to:
"script: {
"build": "rm -rf build && tsc", // delete build folder then complile
}
Upvotes: 17
Reputation: 1
Try to remove "files" in the bottom of the archive. It worked for me.
Upvotes: -1
Reputation: 1
Follow this link, it worked for me: https://bobbyhadz.com/blog/typescript-could-not-resolve-path-with-extensions-ts-tsx
This block to be specific: For example, if you issue a command tsc init, the TypeScript compiler thinks that you want to emit JS for a file called init. Instead, you should use the init flag, tsc --init.
Upvotes: 0
Reputation: 31
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.
Upvotes: 1
Reputation: 1413
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.
Upvotes: 15
Reputation: 17
change the name of your file from .tsc to .ts and it will work :)
Upvotes: -2
Reputation: 457
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.
Upvotes: 2