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.

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

Do you think this is a clever way to circumvent using ENUM for a parameter?

As I continue to explore different coding styles in Typescript and Angular, I recently encountered a method without any comments attached to it. It seems like this method is enforcing that the value passed in must be one of the defined options, but strang ...

The problem with the socket observer issue in the Vue configuration file

I have a situation where I am using the vue.config.js configuration: module.exports = { devServer: { proxy: 'http://localhost:8000' }, publicPath: '/admin/', outputDir: '../backend/admin/' } The issue arises wh ...

Having trouble accessing a DOM element within a Vue component while using vanilla JavaScript

I am attempting to dynamically update data from a Vue component using jQuery in a Webpack project. Below is the code snippet: <template> <div id="container"> <slot>show string!!</slot> <div id="s_container"&g ...

Is it feasible to access a service instance within a parameter decorator in nest.js?

I am looking to replicate the functionality of Spring framework in nest.js with a similar code snippet like this: @Controller('/test') class TestController { @Get() get(@Principal() principal: Principal) { } } After spending countless ho ...

Establish a connection to the ActiveMQ broker utilizing STOMP protocol in an Ionic application

I've recently received an Ionic + Capacitor app that is primarily meant to run on the Android platform. My current task is to incorporate communication with a remote ActiveMQ broker into the app. To achieve this, I utilized the STOMP JS library which ...

Error encountered while compiling an Asp.Net Core project due to exceeding the maximum allowable path length in the

Encountering a critical error during the build process with Visual Studio 2016 update 3 Asp.Net Core. The build is interrupted with the following message: Severity Code Description Project File Line Suppression State Error MSB4018 The "FindC ...

Mono repo project utilizing Angular 4+ and Typescript, enhanced with Bootstrap styling

Looking for a project to practice with Angular 4+ using Typescript and a Bootstrap template. Hoping for a setup where I can just run npm install and ng serve to start. Any recommendations for mono repos would be highly valued! ...

Sign up for a feature that provides an observable exclusively within an if statement

There is an if clause in my code that checks for the presence of the cordova object in the window global object. If cordova is present, it will make a http request and return the default angular 2 http observable. If the application is in a web context wh ...

Errors in Ionic 6 involving the FormBuilder, FormGroup, Validators, FormControl, and ControlContainer

I am currently working on creating a basic registration form using Ionic 6.12.3 ionic -V, Angular CLI version 11.0.5, and npm version 6.14.11. You can find the repository for this project here: Repo. Below is my implementation for the register.page.ts: // ...

Establishing the value of "document.cookie"

Encountering issues while trying to set a cookie using different methods: Method 1: document.cookie = name + "=" + value + "; expires=" + date.toUTCString() + "; path=/"; This method only sets the value up to "name=value" wh ...

Exploring Vue 3 through the lens of class components

Currently, our project is utilizing Vue 2.x and our components are structured as follows: @Component({ template: ` <div> some code .... <div> ` }) export default class class1 extends Vue { @Prop() data: IsomeData; } Vue-class ...

Encountering a '[BABEL] Cannot find module' error message after setting up a new PC

Recently, I configured my development environment on a fresh operating system. When I navigated to my project folder and executed the commands: npm install npm run serve I encountered the following error message: Module build failed (from ./node_modules ...

Utilizing VueJs components within Django with the help of django webpack loader: A step-by-step guide

After following a tutorial on integrating Django and VueJs using django-webpack-loader, I successfully loaded the main.js output from django-webpack-loader to my index.html. Here is the structure of my project directory: - assets - bundles - app. ...

Tips for incorporating auth0 into a vue application with typescript

Being a beginner in TypeScript, I've successfully integrated Auth0 with JavaScript thanks to their provided sample code. However, I'm struggling to find any sample applications for using Vue with TypeScript. Any recommendations or resources would ...

Tips for managing the error message "The key 'myOptionalKey' is optional in the 'myObject' type but necessary in the '{...}' type"

Issue I'm currently working on making a sortable table using a sample table component from Material-UI. I encountered an error when I included an optional key in the Data object. It seems that the type definition in the getComparator function does no ...

"Local Vue App service functions as expected, but encounters issues when deployed on an Apache

My Vue App runs smoothly on localhost when I run npm run wc. However, once I migrate it to the server, I encounter an error. The error message is as follows: Vue warn]: Unknown custom element: <v-app> - did you register the component correctly? For r ...

Issue: Interface not properly implemented by the service

I have created an interface for my angular service implementation. One of the methods in the service returns an observable array, and I am trying to define that signature in the interface. Here's what I have so far: import {Observable} from 'rxj ...

What is the best way to implement multiple templates for a single component?

Is there a way to configure my Home Component based on the user's role? For instance: If the employee is an admin, then the home component should load the template URL designed for admins. Likewise, if the employee is a cashier, then the home compo ...

Using Typescript to extract/calculate types with limitations without the need to explicitly extend or broaden them

I have a function called build that constructs a User object using the provided parameters. I want to define the function in such a way that it recognizes which parameters are being passed and incorporates them into the return value. Initially, I thought ...

Searching for MongoDB / Mongoose - Using FindOneById with specific conditions to match the value of an array inside an object nestled within another array

Although the title of this question may be lengthy, I trust you grasp my meaning with an example. This represents my MongoDB structure: { "_id":{ "$oid":"62408e6bec1c0f7a413c093a" }, "visitors":[ { "firstSource":"12 ...