Exploring the bug in Vue.js and Webpack 5 Federation with TypeScript

Encountering an issue with a new webpack 5 module Federation and TypeScript. I have two separate VueJS applications, both written in VueJS 3. The problem seems to be related to the webpack configuration and the ts-loader, which requires the appendTsSuffixTo option (otherwise, I receive a

Cannot find module '@/App.vue' or its corresponding type declarations.
error).

NOTE: This issue only arises when using Vue 3 or the composition API with Vue 2. Vue 2 (without the composition API) works fine with TypeScript.

The Webpack ts-loader setup looks like this:

   'babel-loader',
    {
       loader: 'ts-loader',

       options: {
          appendTsSuffixTo: [/\.vue$/],
       },
    }

The problem surfaces when utilizing a dynamic federation module:

new ModuleFederationPlugin({
       name: 'main-app',
       filename: 'remoteEntry.js',
       remotes: {
           nav: "nav@http://localhost:5000/remoteEntry.js",
       },
       shared: {
           ...deps,
           vue: {
               singleton: true,
               requiredVersion: deps.vue
           }
       }
   })

and importing it in my App.vue file:

<template>
  <div id="module">
    <h2>Main app</h2>

    <Header />

  </div>
</template>

<script lang="ts">

import {defineComponent} from "vue";

import Header from "nav/Header";

//const Header = () => import("nav/Header"); //The same problem

//const module = "n...émenté...

export default defineComponent({
  name: 'App',
  components: {
    Header
  }
})

</script>

This leads to an error being thrown by Webpack:

TS2307: Cannot find module 'nav/Header' or its corresponding type declarations.

Could this be a bug or is there something wrong on my end? Everything seems to work perfectly for Vue 2.x.x without the composition API.

Answer №1

In order to use an external module in TypeScript, you must declare it properly within your code.

To do this, create a new file with the extension .d.ts at the root directory of your source files, as specified in tsconfig.json. In this file, declare the module using the following syntax:

declare module 'nav/Header'

It is important to ensure that the declaration file is included in your tsconfig.json for TypeScript to recognize it. You can achieve this by updating your tsconfig.json configuration like so:

{
  "include": [
    "**/*.d.ts"
  ]
}

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

Retrieving a distinct value from an Observable

I am currently attempting to extract the monthlyFee value from this specific response body. ...

Modifying elements in an array using iteration in typescript

I'm trying to figure out how to iterate over an array in TypeScript and modify the iterator if necessary. The TypeScript logic I have so far looks like this: for (let list_item of list) { if (list_item matches condition) { modify(list_ite ...

Node.js tutorial: Packing 2D boxes efficiently

Working on a web application using node js and in need of a box packing algorithm to determine the optimal solution. While I could attempt to create an algorithm from scratch (view http://en.wikipedia.org/wiki/Packing_problems), I'm curious if a simil ...

Determine the maximum number of children divs that can be accommodated within a parent div

I am facing a situation where I have an API that returns multiple div elements. In my user interface, there is a parent div in which these child divs need to be displayed. The challenge is that if the child divs are overflowing the parent div, they should ...

Utilizing external libraries in Vue 3 CLI projects

I've been attempting to load modules like Jquery and @tensorflow/tfjs, but I'm having trouble getting them to work. Both have been installed using npm. Everything in my @vue3/cli project works perfectly until I try to import these two modules. ...

Cart Quantity Can Only Be Updated Once Using Ajax

I am currently facing an issue with my page that allows users to increase and decrease the quantity of a product in their cart before proceeding to the checkout confirmation page. I am using Ajax for this functionality, where the backend manipulates the qu ...

Unable to save the session identifier from the response headers while utilizing sessions in react/frappe framework

I am attempting to retrieve the session id (sid) from the response headers in a unique scenario. My client application is situated on a local environment, while my API is hosted on an ERP Next server. Upon sending a login request from the React app, I am ...

Is there a way to dynamically alter the text color in a tag based on its value?

Utilizing ajax technology, I aim to dynamically populate a div tag with values from a table. I believe that implementing a loop is crucial in this scenario, but the challenge lies in executing it correctly. My current setup involves xampp for backend php ...

What is the best way to integrate ag-grid with Observable in Angular 2?

After conducting extensive research on the Internet, I am still struggling to connect the pieces. My angular2 application utilizes an Observable data source from HTTP and I am attempting to integrate ag-grid. However, all I see is a loading screen instead ...

Vue.js not accepting an object as input value

I am working with an input type text in my vue js application. This is the initial code snippet: <input type="text" v-model="answer[index]" > Here is the updated code: <table> <tr v-for="(question_overall, index) in questions"> ...

Is there a way to stop Chrome from creating an endless loop while showing alerts during the focus event, without having to disable and enable the event repeatedly?

Looking for a solution to prevent an infinite loop of alert messages in Google Chrome when clicking on cmbMonkeys. The workaround for cmbPeople is working fine, but I'm curious if there's another way to handle alerts on focus or blur events with ...

What is the best way to compare two sets of arrays and generate a new one with unique key-value pairs?

I have two arrays and I want to extract specific key-value pairs from each and combine them into a new array, handling duplicate entries. First Array : [ {id: 2, name: "HSBC", status: "YES"}, {id: 3, name: "Morgan Stanley&quo ...

Completely obliterate all charts when using the ngDestroy method in Angular 4

In this function, I am responsible for drawing the charts: private drawCharts(charts) { this.charts = charts.map((chart, i) => { this.options.title.text = chart.title; const options = { type: this.type || 'bar' ...

The final thumbnail fails to appear in the visible display (react-responsive-carousel)

I am currently facing an issue with displaying a series of images using react-responsive-carousel. When the images exceed a certain size causing the thumbnail section to become scrollable, the last thumbnail is always out of view. Although I have impleme ...

Creating a dynamic video background using Html5 and CSS with a scrolling attachment

video { width: 100%; z-index: 1; position: fixed; } I tested this code and it works well, however, the video remains fixed across the entire body of the page... ...

Encountering an Uncaught TypeError within a 'forEach' loop due to it being identified as not being

Here is some HTML code: <div class="grid-container"> <div class="grid" id="grid-div"> <div class="cell1"></div> <div class="cell2"></div> ...

ng-include not functioning properly within ng-table

In the table, there is a data structure <tr ng-repeat="question in $data" ng-include="'/views/partials/questionList.html'"></tr> Within the questionList.html file: <td class="top-td" data-title="'ID'" sortable="&ap ...

Infinite Scrolling in React: Troubleshooting Issues with the dataLength Parameter

A function called newsFeed is utilized within the useEffect hook to make a request to an endpoint for fetching posts made by the logged in user and users they follow. The retrieved data is then saved to the state: const [posts, setPosts] = useState([]) con ...

Creating a dynamic dropdown menu to display nested arrays in Vuejs

I have some important data https://i.sstatic.net/Cq2t6.png Challenge I'm facing difficulty in accessing the tubes array within my data Solution script data() { return { types: [] } }, m ...

Retrieving data attributes from model within a Backbone view using Underscore template

I have a Backbone.js view that I'm working with: var StreamV = Backbone.View.extend({ tagName: 'div', className: 'stream', events: { }, initialize: function () { this.listenTo(this.model, 'change' ...