Reading time·2 min
The error "Could not resolve the path with the extensions '.ts', '.tsx'"
occurs when we incorrectly use the tsc
command.
To solve the error, make sure to only pass valid flags to tsc
, e.g.
tsc --project tsconfig.json
, tsc --init
or tsc --watch
.
Here is an example of how the error occurs.
tsc . # 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
The error is caused when we pass incorrect parameters or flags to the tsc command.
TypeScript thinks that we only want to emit JS for a file called .
when we use
the tsc .
command and it errors out.
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
.tsc
commandsHere are some common commands you could use.
# Run a compile based on a backwards look through the fs for a tsconfig.json tsc # Initializes a TypeScript project and creates a tsconfig.json file tsc --init # Watch input files tsc --watch # Show the compiler's version tsc --version # Emit JS for just the index.ts with the compiler defaults tsc index.ts # Emit JS for any .ts files in the folder src, with the default settings tsc src/*.ts # Emit files referenced in with the compiler settings from tsconfig.production.json tsc --project tsconfig.production.json # Emit d.ts files for a js file with showing compiler options which are booleans tsc index.js --declaration --emitDeclarationOnly # Emit a single .js file from two files via compiler options which take string arguments tsc app.ts util.ts --target esnext --outfile index.js
A helpful command you can use for debugging is tsc --all
. The command shows
all of the options.
Alternatively, you can look for the syntax of the command and the available options in the tsc cli reference.
If you get an error that tsc is not recognized or not found, click on the link and follow the instructions.
I've also written a detailed guide on how to check which version of TypeScript is installed.