Having trouble with your Typescript *.ts files?

Having trouble understanding why the command

tsc *.ts

isn't functioning correctly. The error message TS6053: File '*.ts' not found keeps appearing. Any suggestions on how to compile all the .ts files within a directory? Thank you!

Answer №1

When executing the tsc command in the terminal without having a tsconfig file available, remember to provide it with a specific file name, such as app.ts - the command will handle the dependencies for you, eliminating the need for wildcards.

However, if you do have a tsconfig.json file, simply run the tsc command without specifying a file name argument and it will utilize the configuration settings, which may include the use of wildcards.

Answer №2

If you simply enter "tsc" in the terminal, it will automatically compile all of your TypeScript (.ts) files into JavaScript (.js) files. To bundle them together, you can use the command "tsc --outFile mybundle.js".

It's important to clarify that by bundling, it means consolidating all your JavaScript code into a single file. For more advanced configurations, consider setting up a tsconfig.json file as suggested by others.

Answer №3

Today, I ran into an issue while trying to execute 2 files in a folder that I created a few months ago when I first started learning Angular. Interestingly, I did not encounter this problem back then.

Important to note: The file had remained untouched since the initial modification and executed successfully at that time.

Although not the most ideal solution, the following workaround worked for me today.

Situation: In a folder containing "LikesComponent.ts" and "main.ts" files, I needed to execute both TS files to obtain the output. So I ran

tsc *.ts && node main.js

An error popped up:

error TS6053: File '*.ts' not found.
Found 1 error.

However, running the command below resolved the issue:

tsc LikesComponent.ts main.ts && node main.js

Answer №4

Dealing with a similar issue myself, you might want to give this command a shot: tsc --outFile file.js file.ts

Answer №5

It appears that the solution marked as correct may not be the best approach, especially if you are new to Angular and following tutorials by Mosh.

The alternative solution would be to simply execute the root file where all other modules are imported. In my case, this file is main.ts, and below is the command I used to run it:

$tsc main.ts && node main.js

Answer №6

If you're operating on a linux system, try this out:

find . -name "*.ts" | xargs tsc

The xargs utility will transform the results of the find command into arguments for the tsc compiler.

Keep in mind that this approach also covers subdirectories:

find src/ -name "*.ts" | xargs tsc

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to easily organize a TypeScript dictionary in a straightforward manner?

My typescript dictionary is filled with code. var dictionaryOfScores: {[id: string]: number } = {}; Now that it's populated, I want to sort it based on the value (number). Since the dictionary could be quite large, I'm looking for an in-place ...

Automatically injecting dependencies in Aurelia using Typescript

Recently, I started working with Typescript and Aurelia framework. Currently, I am facing an issue while trying to implement the @autoinject decorator in a VS2015 ASP.NET MVC 6 project. Below is the code snippet I am using: import {autoinject} from "aure ...

A new feature introduced in TypeScript, expression-level syntax was not present until it was added in JavaScript

Celebrating a Decade of TypeScript remarked that "It’s quite remarkable how the design goals set for TypeScript have stood the test of time." I am particularly intrigued by the goal of "Avoid adding expression-level syntax." One user even brought up thi ...

What is the best way to implement bypassSecurityTrustResourceUrl for all elements within an array?

My challenge is dealing with an array of Google Map Embed API URLs. As I iterate over each item, I need to bind them to the source of an iFrame. I have a solution in mind: constructor(private sanitizer: DomSanitizationService) { this.url = sanitizer. ...

How can I display JSON values without revealing the parent in Angular 5 and Ionic 3?

I am trying to extract values from JSON without the parent keys. Here is the JSON structure I have: [ { "companies": [{ "id": 1, "name": "Prueba", "company_number": "23423423A", "latitude": 241241.12, "lo ...

The best location for storing Typescript files within an ASP.NET Core project

My Typescript app is built on AngularJS 2 with ASP.NET Core, and currently I store my TS files in the wwwroot directory. While this setup works well during development, I am concerned about how it will function in production. I aim to deploy only minified ...

What is the best way to mock an internal function within my route using sinon?

Currently, I have my own internal function defined in the greatRoute.ts file: //in greatRoute.ts async function _secretString(param: string): Promise<string> { ... } router .route('/foo/bar/:secret') .get( async (...) => { ...

The TypeScript compiler is attempting to fetch node modules in the browser while compiling a single output file

After setting up my tsconfig file to build a frontend typescript application with a single output structure, I encountered an unexpected issue: { "compilerOptions": { "target": "es5", "module": "system", "lib": [ "e ...

Injecting Variables Into User-Defined Button

Presenting a custom button with the following code snippet: export default function CustomButton(isValid: any, email: any) { return ( <Button type="submit" disabled={!isValid || !email} style={{ ...

Property of object (TS) cannot be accessed

My question relates to a piece of TypeScript code Here is the code snippet: export function load_form_actions() { $('#step_2_form').on('ajax:before', function(data) { $('#step_2_submit_btn').hide(); $(&ap ...

The specified format of `x-access-token` does not match the required type `AxiosRequestHeaders | undefined`

I am encountering an issue while trying to add an authHeader to the "Service". The error message displayed is: Type '{ 'x-access-token': any; } | { 'x-access-token'?: undefined; }' is not assignable to type 'AxiosRequest ...

The child object in Typescript is characterized by its strong typing system

Looking to convert plain AngularJS code to Typescript? Take a look at this example: app.someController = function ($scope) { // var $scope.Data = null; var $scope.Data: SomeCollection = null; I need to associate Data with scope and specify it as type ...

Returns false: CanActivate Observable detects a delay during service validation

Issue with Route Guard in Angular Application: I encountered an issue with my route guard in my Angular application. The problem arises when the guard is active and runs a check by calling a service to retrieve a value. This value is then mapped to true or ...

My Angular Router is creating duplicate instances of my route components

I have captured screenshots of the application: https://ibb.co/NmnSPNr and https://ibb.co/C0nwG4D info.component.ts / The Info component is a child component of the Item component, displayed when a specific link is routed to. export class InfoComponent imp ...

Encountering a SonarQube error message stating "Unnecessary 'undefined' should be removed" when using "undefined" as a function argument

When calling a function, I have been passing "undefined" multiple times as a parameter. However, the SonarQube report is flagging an error stating "Remove this redundant undefined". https://i.stack.imgur.com/YhOZW.png It should be noted that the function ...

Basic Karma setup with Typescript - Error: x is undefined

I am trying to configure a basic test runner using Karma in order to test a TypeScript class. However, when I attempt to run the tests with karma start, I encounter an error stating that ReferenceError: Calculator is not defined. It seems like either the ...

Require using .toString() method on an object during automatic conversion to a string

I'm interested in automating the process of utilizing an object's toString() method when it is implicitly converted to a string. Let's consider this example class: class Dog { name: string; constructor(name: string) { this.name = na ...

Differentiating Typescript will discard attributes that do not adhere to an Interface

Currently, I am working with an API controller that requires a body parameter as shown below: insertUser(@Body() user: IUser) {} The problem I'm facing is that I can submit an object that includes additional properties not specified in the IUser int ...

How can I set up TypeScript warnings in Visual Studio Code to display as errors?

Take this scenario for instance async function a() { await null; } In VS Code, there is a minor warning about using await: 'await' has no effect on the type of this expression. ts(80007) Is there a way to elevate that warning to an error in b ...

Formik QR code reader button that triggers its own submission

I recently developed a custom QR code reader feature as a button within the Formik component customTextInput.tsx, but I encountered an issue where clicking on the button would trigger a submission without any value present. The following code snippet show ...