Preventing Circular Dependencies in RollupJS and TypeScript: Ensuring Build Failure When Circular Dependencies are Detected

I recently created a React component library using RollupJS (2.7) and TypeScript (3.9.10), and I encountered an issue with circular dependencies being reported:

>> yarn build
(!) Circular dependency
src/index.ts -> src/components/index.ts -> src/components/Button/index.ts -> src/components/Button/Button.tsx -> src/index.ts

Despite the circular dependencies, the build process still manages to complete:

created ./dist/index.esm.js, ./dist/index.js in 4.3s

I searched through the tsconfig and rollup.config.js documentation for any configuration changes that could help address circular dependencies, but found none.

Is there a way to configure the tools (such as tsconfig or rollup.config) to automatically fail the build if a circular dependency is detected?

Answer №1

After stumbling upon this informative comment, I discovered the existence of the onwarn API.

Although there isn't an official documentation for onwarn in Rollup, I managed to resolve my issue by including the following code snippet at the top level of my rollup.config.js:

onwarn: (message) => {
  // fail build if circular dependencies are found
  if (message.code === 'CIRCULAR_DEPENDENCY') {
    console.error(message);
    process.exit(-1);
  }
},

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

Upon updating the file extension from js to ts, Ionic is no longer able to locate the module

I have been using the Ionic framework to develop a mobile application by following the guidance provided at http://ionicframework.com/docs/v2/getting-started/tutorial/. ionic start my-mobileapp sidemenu --v2 After that, I launched the app in a browser us ...

Combining JavaScript files can cause conflicts with duplicate identifiers when using Typescript namespaces

As a newcomer to Typescript, I am grappling with the concept of namespaces and how to reference Interfaces that are defined in separate files. Coming from a .NET C# background, I am used to creating each class and interface in their own file. INationalRai ...

Displaying an error message following the dynamic retrieval of the input field's value

How can I display an error message when a specific field with a value of 0 is not filled out in my Angular reactive forms? In my form, I have added a dropdown which is mandatory and I have implemented validators to ensure it is required. The validator work ...

Using TypeScript or JavaScript, set object keys as fields of a class

I am looking for a way to update the properties of this class dynamically using an object export default class Foo { private accessKey: string; private workspaceId: string; private api: AxiosInstance; public bar: string; public name: s ...

Is there a way to use Jest spyOn to monitor a function that is returned by another function?

I'm curious about why the final assertion (expect(msgSpy).toBeCalled()) in this code snippet is failing. What adjustments should be made to ensure it passes? it('spyOn test', () => { const newClient = () => { const getMsg = ...

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 ...

Is there a way to create a universal getter/setter for TypeScript classes?

One feature I understand is setting getters and setters for individual properties. export class Person { private _name: string; set name(value) { this._name = value; } get name() { return this._name; } } Is there a w ...

Accessing a variable within a function in Angular

Recently I started working with Angular and encountered an issue while trying to access a variable inside a function. Below is the code snippet that's causing me trouble: mergeImages() { var imgurl; var canvas: HTMLCanvasElement = this.canv ...

Increasing the number of service providers in Angular2-4 directives

Is there a way to apply both * to a string? Below is the code snippet I am working with: <a class="sidenav-anchor" *ngIf="!item.hasSubItems()" md-list-item md-ripple [routerLink]="[item.route]" routerLinkActive="active" [routerLinkActiveOptions]="{ex ...

Attempting to transfer files to and from Firebase storage

Having trouble with my React Native app. I am trying to upload files, whether they are pictures or PDFs, but once uploaded, I can't seem to open them. However, "The files are getting uploaded to the storage." export const uploadToStorage = async (docu ...

CPU usage spikes after launching a Cordova project in Visual Studio 2015 RTM

If you're looking for the source code of the project, you can find it at https://github.com/Yaojian/Ionic-TypeScript-Starter/. I decided to create a Visual Studio project by forking https://github.com/Justin-Credible/Ionic-TypeScript-Starter/ and fol ...

Implementing onClick event handling in Material UI components using Typescript

I am attempting to pass a function that returns another function to material UI's onTouchTap event: <IconButton onTouchTap={onObjectClick(object)} style={iconButtonStyle} > <img alt={customer.name} className="object-img" src={obj ...

The type 'Observable<DataListItem[]>' cannot be assigned to type 'DataListItem[]'

Error message details: "The type 'Observable' is not compatible with the type 'DataListeItem[]'. The 'includes' property is missing in the 'Observable' type." I am currently using the Material Table Schematic an ...

Comparing Node.JS using Typescript versus Javascript to Ruby On Rails

My question can be simplified as follows: 1. Does Ruby perform as well as Node with MongoDB? 2. Should I use Typescript or JavaScript with Node? I come from a .NET background (ASP.NET MVC) and am now venturing into creating an Angular project with a Mongo ...

Having difficulty forming queries correctly using TypeScript, React, and GraphQL

Apologies for the potentially naive question, but I am new to working with GraphQL and React. I am attempting to create a component that contains a GraphQL query and incoming props. The props consist of a query that should be passed into the GraphQL query. ...

What is the process of transforming a basic JavaScript function into a TypeScript function?

As a Java developer diving into TypeScript for frontend development, I've encountered a simple JavaScript code snippet that I'd like to convert to TypeScript. The original JavaScript code is: let numbers = [123, 234, 345, 456, 567]; let names = ...

Expanding Form Arrays with Dynamically Generated Fields

One challenge I'm facing involves a form array structured as follows: this.myForm = this.fb.group({ arr: this.fb.array([this.createItem()]) }) I have the ability to dynamically append fields to the array using the following methods: ...

The validator is incorrectly diagnosing the input as 'invalid' when in reality it is not

Currently, I am working on creating a text field that must not be empty and should also not start with a specific set of characters (let's say 'test'). For example, I want testxyz or an empty field to be considered invalid, while anything e ...

Vue 3 components array typified with Typescript

I'm attempting to establish an array of components representing various steps. Initially, I attempted to assign the type to these steps: const steps = ref<Component[]>([ Component1, Component2, Component3, ]); However, this approach is n ...

Angular 2 - Managing the status of checkboxes in a list of checkboxes

I recently started using Angular 2 with Typescript and I am working on creating a list of checkboxes to manage their states. Similar to how some shopping websites function, the checkboxes represent different companies. Users can select multiple checkboxes ...