Workspace watch mode does not update Typescript definitions

Greetings to all who are reading this,

I have created a React micro-frontend project using SPA v5.9, Webpack v5.75, Babel-loader v9.1, Ts-loader v9.4, and Yarn workspace v3.5. The project structure is very basic:

  • Root SPA => Package Root
  • Application SPA => Package App1
  • Utils SPA => Package Utils1
  • React lib Utils SPA => Package Utils2

My current challenge arises when running the app on Webpack dev server. If I add a new function to Utils1 and try to use it in App1, TypeScript throws an error stating that there is no existing export for this function.

The application runs without issues, so I suspect it's a misconfiguration of either Webpack, loaders, or TypeScript settings. Unfortunately, I am not well-versed in this specific setup and haven't been able to find a solution on Stack Overflow or GitHub repositories.

To see more details about the configuration used, you can visit my project here.

My main question is: How can I resolve the TypeScript error occurring when using Webpack?

I believe that sharing the solution from my repository could benefit others who are facing similar challenges in structuring their projects. So, it would be great to find and share a resolution :)

An interesting observation is that the updated d.ts files of Utils1 are successfully created in my dist directory by Ts-loader and emitted in App1 as assets by path ../../utils1. However, this seems insufficient.

Here are some logs from the console when adding a new function:

...

And here is the error log when trying to utilize that function:

...

Answer №1

Today, I utilized my brain wisely and successfully configured webpack to run smoothly.

I suspected that the configuration issue stemmed from the fork-ts-checker-webpack-plugin embedded by webpack-config-single-spa-ts v4.1.3. Upon further inspection of its configuration, I discovered that it did not align with the documentation provided.

          new ForkTsCheckerWebpackPlugin({
            typescript: {
              mode: "write-references",
            },
          }),

According to the fork-ts-checker-webpack-plugin documentation, when using

mode: "write-references"
, we also need to set build: true. After some research, I realized that enabling the build mode of tsc would compile our reference project unnecessarily. I updated the configuration as follows:

      new ForkTsCheckerWebpackPlugin({
        typescript: {
          mode: "readonly",
          build: true,
        },
      }),

This adjustment met my expectations and worked seamlessly during development under webpack:

  • If I modify a method in the utils1 project used by app1, it will generate a valid typescript error :)
  • If I add a function to utils1 and call it from app1, there are no complaints about unknown exports from utils1 :)

This configuration only affects packages that use references in tsconfig, excluding the root app and utils in my case.

I also optimized the configuration for my spa utils by keeping it empty to default as my utils do not depend on other packages. This results in in-memory files:

new ForkTsCheckerWebpackPlugin({}), // Overrides the conf mode: "write-references" from singleSpaDefaults. We use in-memory readonly definition, assuming you run your production build with tsc.

All these modifications can be found in the develop branch of my repository.

In the upcoming commits, I plan to add fast-refresh and CSS prefixing by package, along with other features. Feel free to engage in discussions or raise issues if you have suggestions for enhancing the repository :)

Initial investigation findings:

I believe I have narrowed down the source of the error messages originating from the fork-ts-checker-webpack-plugin plugin. Removing it from the webpack configuration in the app1 webpack conf has resolved the errors.

I pursued this approach because the fork-ts-checker-webpack-plugin operates in a separate process, potentially causing asynchronous issues with webpack.

However, I am uncertain whether by removing it:

  • I have completely disabled TypeScript checking
  • Or simply shifted the responsibility of type checking solely to the ts-loader.

What is your perspective on this?

I intend to explore any potential side effects further.

Find the update in this branch of my repository

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

Conflicting TypeScript enum types: numbers and numbers in NestJS/ExpressJS

Incorporating types into my NestJS server has been a priority. After creating a controller (a route for those who prefer Express), I attempted to define the type for params: public async getAllMessages( @Query('startDate', ValidateDate) start ...

Reactjs Promise left hanging in limbo

How can I resolve the pending status of my promise? I have a modal with a form submit in it, where I am trying to retrieve the base64 string of a CSV file. While my code seems to be returning the desired result, it remains stuck in a pending state. c ...

Using React hooks and Typescript: I was expecting to see an assignment or function call, but instead, an expression was

After working as a React developer for quite some time, my workplace recently introduced Typescript, which I am still getting familiar with. I implemented a custom hook for managing cookies, but the function it returns is generating an error. Here's ...

Issue with Dates in Typescript array elements

When attempting to compare different Date elements in my code, I encountered an issue. I have two date elements representing date formats but am unable to compare them because I keep receiving the error message "core.js:6237 ERROR TypeError: newticketList. ...

What is the best way to iterate over an Angular HTTP Response?

As a newcomer to Angular, I am working on mastering the process of uploading files and calling an API for validation. The API responds with a list of JSON validation errors based on specific file values. I am currently struggling to iterate through these ...

Every time I clear the information, it seems to be instantly replaced with new data. How can I prevent it from constantly refilling?

When I press the remove button on my application, it successfully deletes the data in a field. However, it also automatically adds new data to the field which was not intended. I am seeking assistance on how to keep those fields empty after removing the ...

Is there a way to set a default value for an Angular service provider?

Imagine an Angular Service that encapsulates the HTTP Client Module. export class HttpWrapperService { private apiKey: string; } Of course, it offers additional features that are not relevant here. Now I'm faced with the task of supplying HttpWr ...

Binding an ID to an <ion-textarea> in Ionic 3

Can an ID be assigned to an ion-textarea? For example: <ion-textarea placeholder="Enter your thoughts" id="thoughtsBox"></ion-textarea> Thank you very much ...

"Launching" conduit for Observable

Is there a way to attach two pipes to an HttpClient request in order to execute functions at the beginning and end of the request? I have discovered the "finalize" operator for executing a function when the request is finished, but I am looking for an equi ...

Differences between ts-loader and babel-loader when working with TypeScript in webpack

Recently, I set out to compare the compiled output code between these two configurations. ts-loader { test: /\.tsx?$/, use: 'ts-loader', } babel-loader use: { loader: 'babel-loader', options: { p ...

The selected image should change its border color, while clicking on another image within the same div should deselect the previous image

I could really use some assistance! I've been working on Angular8 and I came across an image that shows how all the div elements are being selected when clicking on an image. Instead of just removing the border effect from the previous image, it only ...

Do you believe this problem with transpilation has been properly reported to babel-jest?

I recently encountered a problem in the jest project regarding babel-jest transpilation. I added some code that appeared to be error-free, but caused transpilation to fail completely. Although the issue seemed related to a Typescript Next project, there a ...

Best practices for transferring date objects between a frontend developed in JavaScript/TypeScript and a backend built in ASP.net Core 5

An exciting project I am working on involves a web application with a backend REST web API developed in ASP.net Core 5 and a frontend Angular application written in TypeScript. One of the APIs from the ASP.net backend returns an instance of a C# object de ...

Using RxJS to merge various HTTP requests into a unified and flattened observable array

Struggling with combining multiple http get requests simultaneously and returning them as a unified, observable array. In my current setup, the method returnNewCars() retrieves Observable<ICar[]> by executing a single http get request. However, in t ...

Adjusting the timing of a scheduled meeting

Is there a way for me to update the time of a Subject within my service? I'm considering abstracting this function into a service: date: Date; setTime(hours: number, mins: number, secs: number): void { this.date.setHours(hours); this.date.s ...

Using Webpack 4 and React Router, when trying to navigate to a sub path,

I'm currently working on setting up a router for my page, but I've encountered a problem. import * as React from 'react'; import {Route, Router, Switch, Redirect} from 'react-router-dom'; import { createBrowserHistory } from ...

What could be causing the inability to update a newly logged-in user without refreshing the page?

Hello, I have encountered an issue with my application that involves registration and login functionality. The problem arises when a new user logs in, as I must refresh the page to get the current user information. I am currently using interpolation on the ...

Leverage the new Animation support in RC 5 to animate each item in an *ngFor list sequentially in Angular 2

I have a unique component that retrieves a list of items from the server and then displays that list using *ngFor in the template. My goal is to add animation to the list display, with each item animating in one after the other. I am experimenting with t ...

Retrieve the Document ID from Firebase

I'm currently exploring the functionality of Firebase and enhancing my workflow with "react-firebase-hooks". Is there a way for me to retrieve both the doc id and doc data simultaneously and pass them as props? Currently, I am only able to access the ...

Guide on mocking a function inside another function imported from a module with TypeScript and Jest

I have a function inside the action directory that I want to test: import { Action, ActionProgress, ActionStatus, MagicLinkProgress } from '../../interfaces' import { areSameActions } from '../actionsProgress' export const findActionPr ...