Is it possible for source maps in the sequence of src ➜ tsc ➜ rollup ➜ `source maps` to accurately lead back to the

After reading an article about bundling ES2015 modules with TypeScript and Rollup, I decided to try it out myself.

In the example provided, there is a file named math.ts

export function square(x: number) {
    return x ** 2;
}

export function cube(x: number) {
    return x ** 3;
}

and another file named main.ts

import { square } from "./math";

console.log(square(3));

Following the command:

tsc -t ES5 -m es2015 && rollup -f es -o app.js -m -i main.js

A new file app.js is generated

function square(x) {
    return Math.pow(x, 2);
}

console.log(square(3));
//# sourceMappingURL=app.js.map

The issue arises when the source map in .js output file points to the compiled JavaScript files instead of the original TypeScript files. How can I fix this?

Answer №1

A great solution would be to use the rollup-plugin-sourcemaps package.

Check out the instructions provided in the link above for how to implement this plugin.

You can also explore Alex Jover's typescript-library-starter, which includes not only this plugin but others that may help with different issues. In addition, he mentions:

If you are already using rollup-plugin-babel, consider utilizing the inputSourceMap option instead of adding another plugin.

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

Establish an enumeration using universally recognized identifiers

I have a JavaScript function that requires a numerical input, as well as some predefined constants at the top level: var FOO = 1; var BAR = 2; The function should only be called using one of these constants. To ensure type safety in TypeScript, I am att ...

What is the best way to confirm the return type of a React.Component instance?

When working with TypeScript, there is a React Component called Cell: class Cell extends Component<void, void> { ... } Using it like this: <Cell /> The return type being received is JSX.Element. However, I want to make sure that the return ...

Arranging table columns in Angular 2

Having trouble organizing the columns of my table using Angular 2 The transform code for the pipe is as follows: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'orderBy' }) export class OrderByPipe implements Pipe ...

Broaden the TypeScript interface with indexed types

Imagine a straightforward indexed interface: interface FormData { [K: string]: string; } This little fella works like a charm. However, there comes a time when I want to allow a property to be an array of strings. interface AcmeFormData extends Form ...

Issue with updating values in a ReactJS function

My ReactJs function is designed to display a simple dialogue box and update a value for the parent component. Here is an example of how the function is structured: export function MyDialogue(props: IMyProps) { var myValue = 0; return ( ...

The process of removing an item from an array when a checkbox is deselected in Angular 4

I am currently working with an array of objects where each object contains another array. panels = [{ Id: "26cfdb68-ef69-4df0-b4dc-5b9c6501b0dd", Name: "Celiac test", Tests: [{ Id: "e2bb4607-c227-4483-a3e9-55c1bc5a6781", Name: "test 1 (D ...

Utilizing TypeScript's Type Inference to Simplify Function Combinations

I'm facing a challenge with what should be simple. The types aren't coming through as expected when trying to combine a couple of functions. Is there a way to have TypeScript infer the types without explicitly specifying them? import { pipe, map ...

How to dynamically incorporate methods into a TypeScript class

I'm currently attempting to dynamically inject a method into an external class in TypeScript, but I'm encountering the following error. Error TS2339: Property 'modifyLogger' does not exist on type 'extclass'. Here's the ...

Tips on how to dynamically uncheck and check the Nebular checkbox post-rendering

I incorporated a nebular theme checkbox into my Angular 8 App. <nb-checkbox [checked]="enable_checked" (checkedChange)="enable($event)">Enable</nb-checkbox> I am able to update the checkbox using the Boolean variable "enable_checked". Initia ...

Assign a variable to the key of a statically typed object in TypeScript

Is there a cleaner way to explicitly type an object and assign key-value pairs where the keys are variable names? I found a solution using ES2015 template literals and JSON.parse() that looks like this: interface MyObj { [propName: string]: number; } ...

Issue with playing audio file using HowlerJS

Having trouble playing a .mp3 file in my project directory with Howler. I'm not sure if there's an error in my src. When I tried playing an online hosted audio file, it worked fine. I've placed the audio file in the same directory as Slideon ...

Modify the selection in one dropdown menu based on the selection in another dropdown menu using Angular 8

When I have two dropdowns, I aim to update the second dropdown with a matching JSON object based on the value selected in the first dropdown. JSON this.dropdownValues = { "mysql 8": { "flavor": [ "medium", ...

Angular - Retrieve array of child components upon initialization

Currently, I am utilizing Angular 10 for a personal side project. Within this project, there is a specific page that, upon loading, fetches a collection of entries (in this case, primarily spells) from the server and displays one child component (<app-s ...

React Native TextInput utilizing FieldRenderProps

When working with final-form in React-Native, I encountered an issue while creating a custom TextInput. It seems that specifying the type for FieldRenderProps is resulting in an error: TS2769: No overload matches this call. Overload 1 of 2, '(props: T ...

Define a new type in Typescript that is equal to another type, but with the added flexibility of having optional

I have 2 categories: category Main = { x: boolean; y: number; z: string } category MainOptions = { x?: boolean; y?: number; z?: string; } In this scenario, MainOptions is designed to include some, none, or all of the attributes that belong to ...

Steps for generating a signal that postpones the primary signal and promptly resets

I am looking to create a signal that will automatically switch to an underlying signal or memo after a specific delay, and reset immediately if the primary signal is cleared. The code snippet below illustrates my desired functionality. import { render } fr ...

Putting together object attribute values in typescript

Is there a way in TypeScript to restrict the possible values of an object based on specific conditions? Here is my idea: interface IObject = { key1: string; key2: string; key3: "A" | null; key4: (if key3 is 'A' then allow 'va ...

Experimenting with error boundaries by utilizing the React Testing Library and Jest:

I am facing an issue while writing a test for my error boundary higher-order component (HOC). The problem arises when I mock throwing an error in my wrapped component, causing the test to fail because it recognizes the error as a genuine one instead of und ...

Unlock the potential of Power BI with this step-by-step guide on enhancing the Circle Card visual by incorporating unique formatting

Power BI Tutorial: Adding Formatting Options to the Circle Card Visual After completing step 8, I copied the code into my VS Code and encountered 2 error messages: Error message: "import VisualSettings - Module '"./settings"' has no e ...

Struggling to integrate authentication and authorization features into a ReactJS application with Microsoft Azure AD or Database login functionality

We have an application built on React v18 with a backend that includes a Web API and SQL Server database. Our requirement is to authenticate and authorize users using either MS Azure AD or the database. If a user attempts to log in with a username and pas ...