Issue occurs where the system is unable to recognize a defined variable, despite it being clearly defined

I keep encountering an error message stating that my variable is not defined, even though I have clearly defined it just a few lines above where the error occurs.

The reason behind this error is baffling to me, as I cannot identify any potential triggers for it.

Interestingly, this error exclusively manifests itself in the browser, whereas there are no issues reported in the terminal where my application is actively running.

https://i.sstatic.net/rCjO1.png

Snippet from main.ts

import { createApp } from 'vue'
import { History, IHistory } from '@/modules/history/History'
import App from './App.vue'
import ElementPlus  from 'element-plus'

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $hist: IHistory;
  }
}

const app = createApp(App)
app.use(ElementPlus, { size: 'small' })
app.config.globalProperties.$ELEMENT = { size: 'small' }
app.config.globalProperties.$hist = History.instance()
app.mount('#app')

Exported console logs

log.js?1afd:24 [HMR] Waiting for update signal from WDS...
main.ts?cd49:13 Uncaught ReferenceError: ElementPlus is not defined
    at eval (main.ts?cd49:13)
    at Module../src/main.ts (app.js:1798)
    at __webpack_require__ (app.js:849)
    at fn (app.js:151)
    at Object.1 (app.js:2027)
    at __webpack_require__ (app.js:849)
    at checkDeferredModules (app.js:46)
    at app.js:925
    at app.js:928
eval @ main.ts?cd49:13
./src/main.ts @ app.js:1798
__webpack_require__ @ app.js:849
fn @ app.js:151
1 @ app.js:2027
__webpack_require__ @ app.js:849
checkDeferredModules @ app.js:46
(anonymous) @ app.js:925
(anonymous) @ app.js:928

Answer №1

I have identified the root cause of my issue and I now understand that it is not a problem but rather the intended behavior.

The reason for this behavior can be attributed to a babel plugin called babel-plugin-import.

To resolve the issue, all I had to do was import Element+ components instead of directly importing ElementPlus.

Updated main.ts

import { createApp } from 'vue'
import { History, IHistory } from '@/modules/history/History'
import App from './App.vue'
import { ElRow, ElCol } from 'element-plus'

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $hist: IHistory;
  }
}

const app = createApp(App)
app.use(ElRow)
   .use(ElCol)

app.config.globalProperties.$ELEMENT = { size: 'small' }
app.config.globalProperties.$hist = History.instance()
app.mount('#app')

Babel configuration (babel.config.js)

module.exports = {
  plugins: [
    [
      "import",
      {
        libraryName: 'element-plus',
        customStyleName: (name) => {
          name = name.slice(3)
          return `element-plus/packages/theme-chalk/src/${name}.scss`;
        },
      },
   ],
  ],
};

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

Deactivate multiple textareas within a loop by utilizing JQuery/Typescript and KnockoutJS

I am working on a for loop that generates a series of textareas with unique ids using KO data-binding, but they all share the same name. My goal is to utilize Jquery to determine if all the textareas in the list are empty. If they are, I want to disable al ...

The value of additionalUserInfo.isNewUser in Firebase is consistently false

In my application using Ionic 4 with Firebase/AngularFire2, I authenticate users with the signinwithemeailandpassword() method. I need to verify if it's the first time a user is logging in after registering. Firebase provides the option to check this ...

Angular and managing browser tab titles while using window.open()

When the code behind, I am able to open a new browser tab displaying a PDF document using data received as a blob from the server. The functionality works as expected, but I noticed that the title of the browser tab is displayed as some hexadecimal code. I ...

Utilizing Shadow Root and Native Web Components for Seamless In-Page Linking

An illustration of this issue is the <foot-note> custom web component that was developed for my new website, fanaro.io. Normally, in-page linking involves assigning an id to a specific element and then using an <a> with href="#id_name&quo ...

Retrieve class attributes within callback function

I have integrated the plugin from https://github.com/blinkmobile/cordova-plugin-sketch into my Ionic 3 project. One remaining crucial task is to extract the result from the callback functions so that I can continue working with it. Below is a snippet of ...

Guide to developing a personalized useReducer with integrated decision-making and event activation

I am interested in creating a custom hook called useTextProcessor(initialText, props). This hook is designed for managing and manipulating text (string) within a React state. It utilizes useReducer to maintain a cumulative state. Here is the implementation ...

Ascending order cannot be achieved with OrderBy, but descending order can be successfully implemented

I am currently developing a Vue Webapp and facing an issue with sorting data in ascending or descending order. I have written the necessary code for this functionality to work smoothly. template <div class="dropdown-menu dropdown-menu-right" aria-labe ...

Incorporate keyboard shortcuts for easy navigation between previous and next pages

Currently, I have three pages named 'home', 'about', and 'details'. To enhance user experience, I've implemented a keydown event listener on Vue's mounted lifecycle hook for each page. This allows users to navigate b ...

What is the purpose of the tabindex in the MUI Modal component?

Struggling with integrating a modal into my project - it's refusing to close and taking up the entire screen height. On inspection, I found this troublesome code: [tabindex]: outline: none; height: 100% How can I remove height: 100% from the ...

Unable to retrieve query within async function, unable to import graphql queries externally

Is there a way to fetch characters from the parent component when a property changes and utilize these props? I attempted to use the useQuery function within a method and execute this method on prop change, but it seems like something is not functioning co ...

Typescript libraries built specifically for unique custom classes

I am currently exploring the most effective method for creating a class library in Typescript and deploying it to NPM along with a definitions file. The classes within the library serve as models that are utilized by multiple RESTful services. Some of the ...

Animating Angular ng-template on open/close state status

I am looking to add animation when the status of my ng-template changes, but I am unable to find any information about this component... This is the code in my report.component.html <ngb-accordion (click)="arrowRotation(i)" (panelChange)="isOpen($even ...

experiencing unexpected outcomes while testing composable functions with fetch API

There is a composable function called useFetchData used to retrieve data: export const useFetchData = (q?: string) => { const data: Ref<Data | undefined> = ref(); const error: Ref<Error | undefined> = ref(); const isLoading = ref(true) ...

Adding a Unique Variant to Material-UI Component in React/ Typescript

I am currently working on creating a customized component inspired by Material-ui components but with unique styles added. For instance, the Tab component offers variants such as ["standard","scrollable","fullWidth"], and I want to include 'outline ...

Retrieving the User ID from the window's LocalStorage

I am currently working on a DjangoRestFramework / Vue.js application where I have been using this.requestUser = window.localStorage.getItem("username"); to retrieve the logged user. The main purpose of this was to check if a user was logged in or not. Howe ...

Error TS2339 occurs when attempting to migrate to TypeScript due to the absence of the 'PropTypes' property on the 'React' type

Currently in the process of converting a javascript/react project to a typescript/react/redux project. Encountering an issue with this particular file: import React from 'react'; import GoldenLayout from 'golden-layout'; import {Provi ...

Refresh the vue-chart component in a nuxt.js application

I'm currently working on a nuxt project and I need to incorporate some charts into it. I'm using vue-chartjs as a plugin for this purpose. However, the issue I'm facing is that the chart data is fetched after the chart has already been drawn ...

Waiting for Angular's For loop to complete

Recently, I encountered a situation where I needed to format the parameters and submit them to an API using some code. The code involved iterating through performance criteria, performance indicators, and target details to create new objects and push them ...

Experience feelings of bewilderment when encountering TypeScript and Angular as you navigate through the

Exploring Angular and TypeScript for an Ionic project, I am working on a simple functionality. A button click changes the text displayed, followed by another change after a short delay. I'm facing confusion around why "this.text" does not work as exp ...

React: a versatile and type-specific onChange() function

After adding as HTMLInputElement, the error message of Property 'checked' does not exist on type 'EventTarget & (HTMLInputElement | HTMLTextAreaElement)' is resolved. However, I find it interesting that TypeScript doesn't autom ...