Utilize TypeScript Compiler (tsc) without the need for global installation via

Currently, I am tackling a project that needs to be delivered to a group of individuals. This project is written in TypeScript, requiring them to execute the command tsc for compilation.

The issue arises when I run this command following the execution of npm install typescript, as it appears that the command does not exist. However, if I install it with the -g option, then it functions properly.

I am eager for the future recipient of the project to only need to execute npm install without having to install dependencies on their device. Is this feat even achievable?

For context, I am operating on ubuntu 20.

Thank you!

Answer №1

npm install typescript will install it locally within the project directory. To ensure that TypeScript only appears under devDependencies and not dependencies, I recommend adding --save-dev when installing.

You can still use TypeScript in this setup by defining commands in the "scripts" section of your package.json file, like so:

{
    "name": "project-name",
    "version": "1.0.0",
    "description": "...",
    "scripts": {
        "build": "tsc command arguments go here"
    },
    "keywords": [],
    "author": "...",
    "license": "...",
    "devDependencies": {
        "typescript": "^4.5.5"
    }
}

To execute this build command, simply run:

tsc within the node_modules folder and execute it accordingly.

Answer №2

One option is to execute it directly from the node_modules directory.

./node_modules/typescript/bin/tsc

Alternatively, you can utilize npx, a tool that executes binaries from the local node_modules folder.

npx tsc

Answer №3

When your dependencies are installed using a package.json file and you have the yarn package manager installed, you can execute the command yarn 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

What is the best way to execute a function from a parent element within the child element?

Currently, I am working with two components - Navbar (parent) and Setting Menu (Child). const Navbar: React.FC = () => { const classes = useStyles(); const [randomState, setrandomState] = useState(false); const randomStateFunction = () =>{ ...

What is the best way to retrieve all the keys from an array?

I am looking to retrieve the address, latitude, and longitude data dynamically: let Orders= [{ pedido: this.listAddress[0].address, lat: this.listAddress[0].lat, lng: this.listAddress[0].lng }] The above code only fetches the first item from the lis ...

Mapping a response object to a Type interface with multiple Type Interfaces in Angular 7: A step-by-step guide

Here is the interface structure I am working with: export interface ObjLookup { owner?: IObjOwner; contacts?: IOwnerContacts[]; location?: IOwnerLocation; } This includes the following interfaces as well: export interface IObjOwner { las ...

Tips for aligning the arrow of a dropdown menu option

When examining the code provided, I have noticed the clr-select-container with specific attributes as depicted. In the screenshot attached, it displays the clr-select-container. The issue that I am encountering is that the inverted arrow is positioned a f ...

Integration of NextAuth with Typescript in nextjs is a powerful tool for authentication

I am diving into NextAuth for the first time, especially with all the new changes in Nextjs 13. Setting up nextauth on my project seems to be a daunting task. I have gone through the documentation here I am struggling to configure it for nextjs 13. How do ...

'Unable to locate the identifier "system" in Angular 2' - troubleshoot this unique error

My routes file contains a reference to 'system' which is causing an error in my Visual Studio Code. The error states that it cannot find the name 'system'. I have attached a screenshot for reference: ...

How can a nullable variable be converted into an interface in TypeScript?

Encountered an issue while working on a vue3.x typescript project. The vue file structure is as follows: <template> <Comp ref="compRef" /> </template> <script lang="ts" setup> import {ref} from "vue& ...

Who is the intended audience for the "engines" field in an npm package - consumers or developers?

As the creator of an npm library, I have included the current LTS versions of Node.js and npm in the package manifest under the engines field. This ensures that all contributors use the same versions I utilized for development: Node.js <a href="/cdn-cgi ...

Using Angular/Typescript to interact with HTML5 Input type Date on Firefox (FF)

Are there any Angular/Typescript projects that are completely built without relying on third-party libraries? I am encountering problems with Firefox and IE11. It works fine on Chrome where the value can be read, but the calendar does not display when us ...

Can a TypeScript generic version of the Y-combinator be successfully executed?

Here is an interesting JavaScript implementation of the Y-combinator: const Y = g => (x => g(x(x)))(x => g(x(x))) //or const Y = f => { const g = x => f(x(x)) return g(g) } I've been thinking, could it be possible to create a TypeS ...

Guide on showing the content of an uploaded file as an object in JavaScript using file reader

When using the file upload function to upload a json file and read its contents, I am encountering an issue where the result is in string format instead of object. How can I display it as an object? Here is my code: .html <div class="form-group"> ...

Access a .docx file on my device by utilizing the Microsoft JavaScript API

In my current project, I am developing a Microsoft Word add-in using TypeScript, React, and the Word API. One of the key features of this add-in will allow users to open a document located on their computer, such as "C:\Test\Test.docx", with just ...

Encountering an issue with Typescript Vue class-based components in Laravel Mix: issue arises when attempting to set property 'render' on an undefined object

I have been using Laravel Mix to compile my Vue components, incorporating TypeScript and class-based components. Each class is exported from the component, and every component is required by the context in the main application script. However, during rende ...

Struggling to create a TypeScript definition file - the JSX element 'SideMenu' lacks any construct or call signatures

I am currently working on creating a type definition file for react-native-side-menu in order to properly declare it. I have integrated it into a TypeScript project, but unfortunately, there are no TypeScript definitions available. Normally, my approach i ...

Utilizing process.env in TypeScript can be a bit tricky as dot notation is not effective for accessing its properties

When I set my scripts to: "start": "NODE_ENV=development nodemon dist/Server.js", I am encountering an issue when trying to access NODE_ENV in my code. Both dot and bracket notation return undefined: The dependencies in my project are: "@types/node": "^8. ...

What is causing the error "Invalid argument, mkdir: ENIVAL" to occur when I try to execute npm?

As I was attempting to install react, an EPERM error occurred. To resolve this issue, I cleared my cache and edited the prefix as per a youtube tutorial. However, I am now encountering an ENIVAL: invalid argument, mkdir error whenever I use npm in a comman ...

VScode has identified potential problems with modules that utilize Angular Ivy, however, this should not cause any major issues

Encountering a problem with using Angular in VSCode, where there seems to be no ngModules due to AngularIvy. The error message indicates an issue with 'CommonModule' not being recognized as an NgModule class: [{ "resource": "[...]src/app/com ...

Troubleshooting a Windows installation error with AWS Amplify CLI

Could use some assistance with installing the aws amplify cli on Windows. I am currently stuck at this point when trying to run the command "npm install -g @aws-amplify/cli". Does anyone have any advice or tips for me? ...

Tips for simulating difficult private attributes within a class during unit testing in TypeScript

Is there a way to mock the value of a hard private property in a unit test? For example, how can I expect something like expect(event.getEventHis()).toBeEqual(['a', 'b']) export class EventController { #event: []; constructor() { ...

Oops! The internal server is throwing an error because it can't find the preprocessor dependency "sass." Have you made sure to install it

After setting up a new VUE 3 and typescript application with vite, I decided to add primevue and primeflex. However, when running npm run dev, an error message appeared as shown below: Can someone guide me on how to resolve this issue? Feel free to check ...