Running the command npx tsc results in no output and does not perform any actions

Currently, I have set up a basic TypeScript configuration to utilize top-level await. It functions as expected and prints the result from the API when I execute tsc && node dist/main.js. However, when I use npx tsc, it only generates a dist folder with main.js and main.js.map without executing anything. I am puzzled by why npx tsc fails to work and what mistake I might be making.

Below is the configuration I am working with:

tsconfig.json

{
  "compilerOptions": {
    "esModuleInterop": true,
    "preserveConstEnums": true,
    "module": "es2022",
    "target": "ES2021",
    "outDir": "./dist",
    "strict": true,
    "sourceMap": true,
    "types": [
      "node"
    ],
    "moduleResolution": "Node",
    "allowJs": true
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules"
  ]
}

src/main.ts

import axios from "axios"

let api = 'https://www.boredapi.com/api/activity'
let response = await axios.get(api)

console.log(`You could ${response.data.activity}`)

Answer №1

npx tsc as well as tsc will achieve the same result with the only variation being the version of tsc they utilize.

  • npx tsc will utilize the local version of tsc in your node_modules if it is accessible
  • tsc makes use of the global tsc installed along with TypeScript

If you are encountering issues where your npx tsc command isn't generating any output, ensure that "noEmit" has been set to false in your tsconfig.json file.

Answer №2

When using the tsc command, its main function is to convert TypeScript code into JavaScript. Simply execute tsc && node dist/main.js to perform the transpilation process and have Node.js start running the main.js file located in the dist directory.

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

Exploring the power of Prosemirror with NextJS through Tiptap v2

Greetings everyone, I am a newcomer to Stack Overflow and I am reaching out for assistance regarding an issue that has arisen. The problem at hand pertains to the development of the Minimum Viable Product (MVP) for my startup which specializes in creating ...

Can you clarify the meaning of "int" in this code snippet?

What does the ?: and <I extends any[] = any[]> signify in this context, and how is it utilized? export interface QueryConfig<I extends any[] = any[]> { name?: string; text: string; values?: I; types?: CustomTypesConfig; } ...

The expression '() => boolean' cannot be assigned to type 'ReactNode'

Could someone please assist me in troubleshooting this TypeScript error? Type '() => boolean' is not assignable to type 'ReactNode'.ts(2322) Here's a snippet of my code for reference: export const Palindrome:React.FC<{}> ...

Error encountered while attempting to utilize 'load' in the fetch function of a layer

I've been exploring ways to implement some pre-update logic for a layer, and I believe the fetch method within the layer's props could be the key. Initially, my aim is to understand the default behavior before incorporating custom logic, but I&ap ...

Enhance your bootstrap accordion by incorporating stylish up and down arrows using the <accordion> element

I am currently developing a sophisticated web application using Angular and TypeScript, and I have decided to incorporate accordions in some sections. The setup for these accordions involves TypeScript/Bootstrap as shown below: <accordion> <acco ...

What is the best way to implement debouncing for an editor value that is controlled by the parent component?

Custom Editor Component import Editor from '@monaco-editor/react'; import { useDebounce } from './useDebounce'; import { useEffect, useState } from 'react'; type Props = { code: string; onChange: (code: string) => void ...

Exploring Pan Gestures in Ionic 3

Looking for information on Pan events in Ionic 3 - not sure if they are related to Cordova or Angular 4? <div class="swipper" #swipper (panleft)="swipe( $event)" (panright)="swipe( $event)" (panend)="swipe( $event) " (panup)="swipe( $event) " (pandown) ...

Breaking up and Substituting text within Angular 8's HTML structure

When I retrieve data from a REST api, I need to split the name parameter at '2330' and insert a line break. For example, if the name is: ABCD 2330 This is My Name, I want the output on my screen to appear as: ABCD 2330 This is My Name // this par ...

I am having trouble with a property that I believe should be recognized but is not

Here is the vocabulary I am working with: type MyHeaders = { Authorization: string; Accept: "application/json"; }; type MyGetOptions = { url: string; json: true; }; type MyOptionsWithHeaders = { headers: MyHeaders; }; type MyPostOptions ...

Transform my Angular implementation to TypeScript programming

After spending a year coding Angular and seeing great progress, the buzz around TypeScript has caught my attention. While there are plenty of tutorials and blogs on the topic, there seems to be inconsistency in the recommendations. How should the app.js fi ...

Fetching FormControl from Directive in Angular

Is there a way to dynamically add validators to a FormControl through a custom Directive? @Directive({ selector: "[idNumber]", }) export class IdNumberDirective implements OnInit { constructor(private formControl: FormControl) { } ngOnInit() ...

Supabase Authentication User Interface Error: Uncaught TypeError - Unable to access properties of null (specifically 'useState')

Concern Whenever I incorporate this Auth component into my login page, I encounter an issue. I am attempting to adhere to the guidelines provided in Supabase Auth with Next.js Pages Directory. If you suspect that this problem stems from a version discrepa ...

Testing the GET method in an Angular service: A guide

I'm currently facing an issue with my service method and unit test setup. Despite writing a unit test for the getter method, the coverage report indicates that this method is not covered. I would appreciate any advice on what might be going wrong in m ...

rxjs "switch to" once the expansion is complete

I am currently working on the following code snippet: const outputFile = fs.createWriteStream(outputPath); const requisitionData = this.login().pipe( map(response => response.data.token), switchMap(loginToken => this.getRequisitions( ...

Add hover effects to components inside MuiButton

I'm currently working with styled components and Material UI, but I'm struggling to add hover styles to the children of MuiButton. Despite following online resources and documentation, I can't seem to make it work. Here's how my jsx is ...

Utilize the power of Wikitude within an Angular 2 application

I am currently working on integrating Wikitude Architect View in Angular 2 by referring to the code at this link. My goal is to implement this code in an Angular 2 compatible way. import * as app from 'application'; import * as platform from & ...

What are the repercussions of labeling a function, TypeScript interface, or TypeScript type with export but never actually importing it? Is this considered poor practice or is there a potential consequence?

I find myself grappling with a seemingly straightforward question that surprisingly has not been asked before by others. I am currently immersed in a TypeScript project involving Vue, and one of the developers has taken to labeling numerous interfaces and ...

Using Mongoose $addToSet to add items to an array only if they are unique

Currently, my code is set up to add new flagDtos using $addToSet without consideration for the uniqueness of item.name. However, I want to change this behavior so that: If item.name is unique, add the new flagDtos object. Otherwise, update the existing fl ...

Using arrow functions in Typescript e6 allows for the utilization of Array.groupBy

I'm attempting to transform a method into a generic method for use with arrow functions in JavaScript, but I'm struggling to determine the correct way to do so. groupBy: <Map>(predicate: (item: T) => Map[]) => Map[]; Array.prototype ...

What are the best methods for testing a function containing multiple conditional statements?

I have a complex function that I want to showcase here, it's quite simple but for some reason, I'm struggling with writing unit tests for it. I don't need the exact unit test implementation, just a general approach or tips on how to handle i ...