Are You Facing the Following error TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” in Typescript? Then You are in right place. In this article, we will try to figure out how this error occurs and what are the possible fixes for this error. First of all, let’s explore how this error occurs.
What is TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” error?
While running a simple Typescript app I am facing the following error.
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
How To Fix TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” Error?
- How To Fix TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” Error?
To Fix TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” Error You can also solve this error without Removing “type”: “module” from package.json First of all install ts-node by running the below command: npm install -g ts-node And now add the following code in your tsconfig.json Just like this: “compilerOptions”: { “esModuleInterop”: true, } Now, run your project and your error must be solved. Thanks.
- TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts”
To Fix TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” Error You just need to remove “type”: “module” from your package.json file and then re-run your project will resolve your error. Thanks.
Solution 1: Remove “type”: “module”
To Fix TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts” Error You just need to remove “type”: “module” from your package.json file and then re-run your project will resolve your error. Thanks.
Solution 2: Install ts-node
You can also solve this error without Removing “type”: “module” from package.json First of all install ts-node by running the below command.
npm install -g ts-node
And now add the following code in your tsconfig.json Just like this.
{
"compilerOptions": {
"esModuleInterop": true,
}
}
Now, run your project and your error must be solved. Thanks.
Solution 3: Run this command
To run your ts file just run this command in your terminal.
node --loader ts-node/esm ./my-script.ts
Hope, now your error must be solved.
Conclusion
It’s all About this error. I hope We Have solved Your error. Comment below Your thoughts and your queries. Also, Comment below on which solution worked for you.
Also, Read
- BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default
- npm ERR! could not determine executable to run
- dynamic import() which is available in all commonjs modules
- require() of ES modules is not supported using recharts
- java.lang.IllegalStateException: Failed to find fragment for React Root View