How to fix “TypeScript emitted no output” error
October 27, 2023
Investigating the error
The configuration of your TypeScript project is controlled by a
tsconfig.json file. If this file contains errors or is misconfigured, it could lead to no output.
- "noEmit" option: Ensure that the
"noEmit"option isn't set to
true. If it's true, TypeScript will perform type-checking but won't generate any output files.
- Output directory: Ensure the
"outDir"option points to a correct and accessible directory.
Source files issue
- No source files: Ensure you have TypeScript files in your project. If the compiler doesn't find any
.tsfiles, it won't emit anything.
- Type errors: If your TypeScript code contains type errors, and the
"noEmitOnError"option is set to
tsconfig.json, the compiler will not produce any output files.
isolatedModules flag without
--isolatedModules flag ensures that every file can be safely transpiled without references to other files. If you use this flag, but you aren't using the
--transpileOnly flag, it can cause the "TypeScript emitted no output" error.
Compiler bugs or third-party issues
Though rare, there's a possibility that a bug in the TypeScript compiler or an issue with a third-party tool or library is causing the problem. If you suspect this might be the case:
- Check if any recent updates were made to your dependencies that might be causing the issue.
- Look for open issues on the TypeScript GitHub repository or the repositories of any third-party tools you're using.
- Consider rolling back to a previous, stable version of TypeScript or the tool in question.
It's possible that command line arguments or another configuration file might be overriding your
tsconfig.json. Ensure that no other configurations interfere with your intended settings.
Fixing the error
Now that you've looked into the potential causes, here's how to address them:
If the issue lies in your configuration:
"noEmit"is set to
- Check the
"outDir"and ensure it's correct.
- If you don't want type errors to halt the output, set
Review your source files
- Confirm that you have
.tsfiles in your project.
- Fix any type errors in your code. Tools like ESLint with TypeScript support can be instrumental in catching these.
Use flags judiciously
If you're using the
--isolatedModules flag, ensure you're also using
Check third-party tools and libraries
Update or rollback versions of tools or libraries if they are the cause of the issue. Remember, always check their documentation or GitHub issues for known problems.
Ensure no configuration overriding
Ensure that there's no conflicting command line argument or another configuration file causing the issue. If you're working within a larger team or using tools like Basedash to view and edit data from your database, ensure that shared configurations or integrations aren't causing the problem.
How to fix the "not all code paths return a value" issue in TypeScript
Working with WebSockets in Node.js using TypeScript
Type Annotations Can Only Be Used in TypeScript Files
Guide to TypeScript Recursive Type
How to Configure Knex.js with TypeScript