Unknown file extension “.ts” for /app/src/index.ts starting node app in combination with nodemon
If you are encountering the error message “Unknown file extension ‘.ts’ for /app/src/index.ts starting node app” when trying to start your Node.js app using nodemon, don’t worry, you’re not alone. This error typically occurs when nodemon is unable to recognize TypeScript files with the “.ts” extension. In this blog post, we will explore a couple of solutions to fix this issue and get your app up and running smoothly.
Solution 1: Configure nodemon to recognize TypeScript files
The first solution involves configuring nodemon to recognize TypeScript files by adding a nodemon.json configuration file to your project’s root directory. This file allows you to specify custom settings for nodemon.
Create a new file named nodemon.json
in your project’s root directory and add the following content:
{
"ext": "ts",
"exec": "ts-node ./app/src/index.ts"
}
In the above configuration, we set the ext
property to “ts” to tell nodemon to watch for changes in TypeScript files. Additionally, we specify the exec
property to run the TypeScript file using ts-node
.
Save the nodemon.json
file and try running your app again with nodemon. The error should no longer occur, and nodemon should be able to recognize and execute your TypeScript files.
Solution 2: Use ts-node-dev instead of nodemon
If the first solution didn’t work for you or you prefer an alternative approach, you can use ts-node-dev
instead of nodemon. ts-node-dev
is a TypeScript execution and reloading tool specifically designed for development environments.
To use ts-node-dev
, first, install it as a development dependency by running the following command:
npm install ts-node-dev --save-dev
Once installed, you can update your package.json
file’s scripts
section to use ts-node-dev
instead of nodemon. Modify the start
script as follows:
"scripts": {
"start": "ts-node-dev ./app/src/index.ts"
}
Save the package.json
file and run your app using npm start
. ts-node-dev
will handle the TypeScript compilation and reloading of your app whenever changes are detected.
Conclusion
The “Unknown file extension ‘.ts’ for /app/src/index.ts starting node app” error can be resolved by either configuring nodemon to recognize TypeScript files or using ts-node-dev
as an alternative. Choose the solution that works best for your project and get back to developing your TypeScript app without any interruptions.
Leave a Reply