The module export in Webpack is undefined

I am looking to utilize webpack for compiling bundle.js in my application. To create a dependency tree, I added imports and exports into my *.ts files. However, I encountered an issue when trying to run the application.

Here is my main.ts file:

import { componentA, componentB } from 'moduleX';
import { componentC } from 'moduleC'

export var componentE: componentA;

$().ready(function () {

    if (componentA.someProperty === true) {

        ...
    }
}

export class MyClass extends componentC {
    ...
}

// end file

This is my moduleX file:

import { componentE } from 'main';
import { componentC } from 'moduleC'

export componentA extends componentC {

    ...

    if (componentE.someProperty === true) {

    }

    ...
}

Upon running build dev and testing my app, I encountered the following error:

Uncaught ReferenceError: componentC is not defined
    at eval (moduleX.js?d3a3:5913)
    at Object../js/moduleX.js (bundle.js?8.0.0:96)
    at __webpack_require__ (bundle.js?8.0.0:20)
    at eval (main.ts?8a84:4)
    at Object../js/main.ts (bundle.js?8.0.0:163)
    at __webpack_require__ (bundle.js?8.0.0:20)
    at bundle.js?8.0.0:84
    at bundle.js?8.0.0:87

While investigating the source in Chrome at moduleX.js?d3a3:5913, I noticed:

var componentA = /** @class */ (function (_super) {
    __extends(componentA, _super);

    //componentA code

}(componentC));

The error occurs at }(componentC));:

Uncaught ReferenceError: componentC is not defined
.

Can you help me identify the problem and provide some guidance?

Answer №1

Can you assist me in identifying the issue?

The root cause is a cyclic dependency.

Solution

To fix it, simply remove the cycle.

Illustration

For example, foo relies on bar which depends on baz, and then ultimately loops back to depend on foo (creating a cycle!).

Resources

A variety of tools are available for this task. I have even developed one myself:

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

Typescript's dynamic React component and its conditional types

I am currently working on a dynamic React component and I am facing an issue with properly passing the correct propType based on the selected component. The error arises when using <SelectComponent {...props.props} /> because the props do not match t ...

Vue.js, when using async await functions, sometimes renders blank results

Currently working on a JavaScript project that requires the use of await/async to fetch data from an API. Here is a snippet of my code: const fetchData = async () => { let data = []; for (let i = 0; i < this.data.length; ...

Upon reinstalling the node_modules in my Nuxt.js project, I encountered the error message "Must use import to load ES Module:~"

After reinstalling node_modules, I encountered an issue where ufo and node-fetch were missing. Upon adding them back in, running npm run dev resulted in an error when opening localhost in a browser. This same error persisted when cloning the project onto ...

Next13, varying data retrieval outcomes between server and client

Embarking on a project with Next13 has been smooth sailing so far. However, as a beginner, I am puzzled by the discrepancy in results I am obtaining from fetching data. Despite setting the component to render on the client side, it also renders on the serv ...

The parameter type is not compatible with the argument type of 'SetStateAction'

I am new to next.js and typescript and I encountered a typescript error in vscode. Even though it does not impact the state variable, I am curious to understand why the error occurs and how to resolve it Error message: "Argument of type 'Movie | ...

NextJS is currently unable to identify and interpret TypeScript files

I am looking to build my website using TypeScript instead of JavaScript. I followed the NextJS official guide for installing TS from scratch, but when I execute npm run dev, a 404 Error page greets me. Okay, below is my tsconfig.json: { "compilerOption ...

Creating a new array by combining data from two arrays: a step-by-step guide

Here is an array I have: response=[ { "mId": "4a993417-3dae-4a85-bb2e-c535d7fda6d7", "title": "test2", "score": "4", "id": "91ce873f- ...

Troubleshooting issue: matTooltip malfunctioning in *ngFor loop after invoking Angular's change

The matTooltip in the component below is rendering correctly. The overlay and small bubble for the tooltip are rendered, but the text is missing (even though it's present in the HTML when inspecting in the browser) and it isn't positioned correct ...

Invoking a subclass's method within a base class in Typescript

Currently, I am in the process of developing a small game project and I am facing a particular challenge that I need a solution for. Within my code, I have a base class called 'Entity' which contains essential methods for its subclasses (objects ...

Update for Module is not available in Tour of Heroes Tutorial

Currently, I am following the "Tour of Heroes" Angular tutorial on angular.io. After incorporating a module named 'heroes' and displaying it, everything seemed to be working fine. The contents of heroes.component.html only featured a single p-ta ...

safeguards for potential parameters

Below is a fixture file with optional properties that I have type guarded: Fixture File- { "profiles": [ { "name": "Laakea", "phoneNumber": "2033719225", "authGroupName": "Drivers" }, { ...

React component's state is not being correctly refreshed on key events

Currently facing an issue that's puzzling me. While creating a Wordle replica, I've noticed that the state updates correctly on some occasions but not on others. I'm struggling to pinpoint the exact reason behind this discrepancy. Included ...

Invalid input: The provided string is not recognized as a valid number

Currently, I am developing a website with Angular that is linked to an ASP.Net backend for database access. The error I am encountering pertains to a custom Async Validator integrated into a Form Control. This validator serves the purpose of verifying if a ...

Guide on typing an asynchronous function that could potentially exit the process in TypeScript?

Is there a way to create an asynchronous function that can exit the process under certain conditions? I would like to use it as follows: function useResult(result:Result): void { // ... } const result: Result | undefined = await getResult(); if (res ...

Unable to resolve issue with loading <lang="scss"> in Vue styles

I'm currently working on a project using webpackconfig. I've installed "sass-loader" and "node-sass," and I've tried various configurations following the official webpack documentation and other sources online to load SCSS files. However, I ...

Can you tell me the data type of IconButtons in Material UI when using TypeScript?

Currently, I am in the process of creating a sidebar using Material UI in Next JS with typescript. My plan is to create a helper function that will help display items within the sidebar. // LeftSidebar.tsx import {List,ListItem,ListItemButton,ListItemIcon ...

"Even after firing the observable through an event, the Async pipe continues to return null

I am currently working with an angular component that incorporates a rich text editor (tiptap v2) and displays the corresponding JSON output. I have created an observable from the update event provided by the editor, aiming to initialize the editor with mo ...

Vue3: The module './assets/logo.png' and its corresponding type declarations are not found

The project was created using the following command: vue create testtype3 Link to image: https://i.sstatic.net/vMuq0.png App.vue: <template> <img alt="Vue logo" src="./assets/logo.png"> <img :src="MyIcon" ...

Ways to display components within the content section of the home component rather than on a distinct page using Angular 5

I recently started working with Angular 5 and I'm encountering an issue with component routing. My goal is to have the app display a login screen when a user first opens it (the login screen should take up the entire browser window). Once the user su ...

Steps for importing Typescript-exporting libraries in next.js

Encountering a challenge while attempting to import a component from a private library that exports Typescript, we are met with the following error message: Module parse failed: Unexpected token (82:7) You may need an appropriate loader to handle this file ...