Home > Mobile >  Unused Component Import solves error Uncaught ReferenceError: Cannot access 'xx' before in
Unused Component Import solves error Uncaught ReferenceError: Cannot access 'xx' before in

Time:07-20

I have this service file, where all other services are stored. Beside importing all services, which are used in the frontend, I store one component in the import section.

import { VacationComponent } from 'app/view/vacation/vacation.component';

The import is not being used in the service file. When removing the import I get the following error:

main-es2015.0cad4195744251a340b5.js:1 Uncaught ReferenceError: Cannot access 'nX' before initialization
at main-es2015.0cad4195744251a340b5.js:1:1825981
at Module.zUnb (main-es2015.0cad4195744251a340b5.js:1:1826937)
at l (runtime-es2015.66c79b9d36e7169e27b0.js:1:552)
at 0 (main-es2015.0cad4195744251a340b5.js:1:5659)
at l (runtime-es2015.66c79b9d36e7169e27b0.js:1:552)
at t (runtime-es2015.66c79b9d36e7169e27b0.js:1:421)
at Array.r [as push] (runtime-es2015.66c79b9d36e7169e27b0.js:1:293)
at main-es2015.0cad4195744251a340b5.js:1:47

. I don't understand how an unused import can fix this error. Also the imported component has no variable "nX" in it. The main file referenced from the error contains a definition of nX which looks like the following:

let nX=(()=>{class t{constructor(t,e){this.service=t,this.dialog=e,this.isChecked=!1}

I see no connection to the imported Component file.

CodePudding user response:

There's a lot of files in your error message, and it's not obvious which one is which.

The main file referenced from the error contains a definition of nX

But is it defined before being used?

Importing an unused component would help resolve this nX variable problem by defining that variable in global scope by itself.

For exmaple, if that unused import does window.nX = "bla";, the variable will no longer be undefined.

It would be helpful if you paste the content of the file where the error occurred - and line where it occurred. Based on given info, my assumption is that you try to use nX before you define it in that file.

CodePudding user response:

The problem is fixed now. The problematic component wasn't the VacationComponent which was imported, but the component which was referenced in the Main file. I am not sure why importing the VacationComponent fixed it at first, but it seems to work now without it since the underlaying problem in the other component is fixed.

  • Related