Compiling TypeScript to JavaScript with Intellij IDEA while preserving the folder hierarchy

Seeking assistance with maintaining directory structure when compiling Typescript to Javascript in Intellij Idea. The current directory setup is as follows:

root
- ts
  - SomeClass1.ts
  - SomeFolder
    - AwesomeClass2.ts
- tsc

The desired compiled file structure should be:

root
- tsc
  - SomeClass1.js
  - SomeFolder
    - AwesomeClass2.js

https://i.sstatic.net/CVQMt.png

This is my Typescript configuration:

https://i.sstatic.net/bl207.png

https://i.sstatic.net/MGYUV.png

However, during compilation, the console displays this error:

https://i.sstatic.net/sI2so.png

  • Setting "Use output path" to "tsc" results in successful compilation, but the directory structure is lost, causing RequireJS to not locate the files.
  • Setting "Use output path" to "tsc\$FileDirRelativeToSourcepath$" generates the error "cannot read the property 'replace' of undefined".
  • Disabling "Use output path" and utilizing "--outDir" with "Command line options" compiles the files into the correct directory, but IntelliJ no longer automatically recompiles changed files.

UPDATE, solution by Nitzan Tomer:

To address this issue, create tsconfig.json in the root directory:

{
  "compilerOptions": {
    "module": "amd",
    "target": "es5",
    "outDir": "tsc",
    "rootDir": "ts",
    "sourceMap": true,
    "declaration": true
  },
  "exclude": [
    "tsc"
  ]
}

Remember to enable "use tsconfig.json" in IntelliJ for proper functionality.

Answer №1

If you utilize the tsconfig.json, you have the ability to define both the rootDir and outDir. By doing so, the directory structure of the rootDir will be preserved in the compiled version within the outDir.

In your specific scenario:

{
    "compilerOptions": {
        "outDir": "tsc",
        "rootDir": "ts",
        "sourceMap": true,
        "declaration": true
    }
}

Save this configuration as tsconfig.json in your main directory, then in IntelliJ/WebStorm, enable TypeScript Compiler and ensure to use the tsconfig.json settings.

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 process for including a scope in an Angular.js HTTP controller?

I am looking to access a $scope variable within this controller in order to utilize Angular functions like ng-click and ng-change in my HTML. Currently, I am only able to use the $http function but unable to execute any Angular methods on it. I am struggli ...

ways to disrupt a timeout

I am attempting to incorporate a functionality similar to this example: https://www.w3schools.com/jsref/met_win_cleartimeout.asp On my personal website: If you enter certain characters in the input field, select one of them, and then pause for 5 seconds, ...

Vue.js is limited in its ability to efficiently partition code into easily loadable modules

My current issue: I am facing a challenge with splitting my vue.js code into chunks. Despite trying multiple examples from tutorials, I am unable to successfully separate the components and load them only when necessary. Whenever I attempt to divide the c ...

Utilizing the scrollTop method to display the number of pixels scrolled on

My goal is to show the number of pixels a user has scrolled on my website using the scrollTop method in jQuery. I want this number of pixels to be displayed within a 'pixels' class. Therefore, I plan to have <p><span class="pixels"> ...

Generate arrays with custom names by parsing JSON data

Currently, I am retrieving data from a MySQL database and converting it to JSON before passing it to a JavaScript class for chart display purposes. The challenge lies in creating arrays required by the chart from the JSON object without manually creating a ...

Utilizing the onscroll feature to trigger a function within a ScrollView

I am facing an issue with an animated view where I need to execute multiple events within the onScroll property. The current onScroll implementation is as follows: onScroll={ Animated.event( [{ nativeEvent: { conten ...

What is the best method for transferring images to a node.js server using Axios?

Is there a method to utilize axios for sending an array of images or a single image to node? My current axios code (implemented in react js on the frontend): onFormSubmit(event){ event.preventDefault(); let payload = this.state; console.log(" ...

How can I programmatically trigger a change event for a dropdown in Vue.js?

I am looking to trigger a dropdown change event within a Vue.js method. <select id="idDropdown" v-model="Result.Value" v-on:change.prevent="changeSelection($event, 'somevalue')"> How can I call the above `cha ...

Display/Conceal JavaScript

I recently implemented a JavaScript function on my website to show/hide specific elements. However, being new to JavaScript, I have encountered some difficulties. I've spent quite some time troubleshooting the code but haven't been able to pinpoi ...

Utilizing REACT to extract values from deeply nested JSON structures

Currently, I am utilizing react to display information from properties stored in a nested JSON. While I can successfully render properties like 'name' and 'id' that are not nested, I encounter an issue when trying to access a nested pro ...

The attribute 'tableName' is not found within the 'Model' type

Currently in the process of converting a JavaScript code to TypeScript. Previously, I had a class that was functioning correctly in JS class Model { constructor(input, alias) { this.tableName = input; this.alias = alias; } } Howev ...

How to incorporate markdown files as strings in Next.js

Is there a way to bring in markdown files as strings in Next.js for use on both the client and server sides? ...

Learn the steps to activate on-page editing feature!

Is there a way to make a section of a webpage editable when a button is clicked? (e.g. edit & view on the same page) For instance, imagine you could click "edit" on this very page (the one you are currently reading), and the title and content become edita ...

Problem with HTML relative paths when linking script sources

Having trouble with a website I constructed using Angular. The problem lies in the references to javascript files in index.html. The issue is that the paths in the HTML are relative to the file, but the browser is searching for the files in the root direct ...

Remove the array element if the value is blank

I have an array with different objects, and I need to efficiently delete the entries where the name is empty, similar to the first and third object in the example below: var myArray = [ { "Name": "", "Value": "" }, { "Name": "aaa", "Value": "bbb" ...

Using the jqueryRotate plugin to rotate an image by 90 degrees

Is there a way to rotate images on a webpage using the JQueryRotate script? I have 10 images that I want to be able to rotate when clicked, but I'm not sure how to implement it. Any assistance would be welcomed. This is the HTML code for the images: ...

Video from Brightcove continues to play even after closing the modal dialog

My concept for opening a Brightcove video in a modal dialog when a button is clicked has been successfully implemented. Below is the code snippet I used for this implementation: Html code: <a class="videoTutorialB" href="#">Watc ...

What is the best way to implement a callback function in JavaScript?

I am looking to update this code to incorporate a callback function. My goal is for the program to first call DynamicLoadScriptForEdit(), followed by calling ExecuteScriptForEdit. Unfortunately, my current implementation is not working as expected. window ...

Retrieving information from Firebase after updating it

My goal is to automatically navigate to a specific ID after adding an item to my realtime database. Despite following the documentation's proposed solution, I am encountering issues with its implementation. Following the use of the push().set() meth ...

Divide the table row and store each cell using regular expressions

Here is the original source text: gi0/1 1G-Fiber -- -- -- -- Down -- -- Access gi0/2 1G-Fiber -- -- -- -- Down -- -- gi0/3 1G-Fiber -- -- -- -- Down -- -- gi0/4 1G-Fiber -- -- -- -- Down -- -- gi0/5 1G-Fiber -- -- -- -- Down -- -- gi0/0/1 1G-Fiber -- ...