Last updated: Mar 21, 2022
Check out my new book
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 --project tsconfig.json,
tsc --init or
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
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,
Here 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, which shows all of
Alternatively, you can look for the syntax of the command and the available options in the tsc cli reference.