Vue throwing ReferenceError when accessing uninitialized variable in Safari browser

Recently, I've encountered a perplexing error message that has me scratching my head. The error message reads as follows:

ReferenceError: Cannot access uninitialized variable.
This error specifically points to the line of code: const app = createApp(App):

// main.js
import {createApp} from 'vue';
import App from 'components/App.vue';

// ...

const app = createApp(App);
// App.vue

<template>
  <template v-if="!started">
    <Start @started="start" />
  </template>
  <template v-else-if="!loaded">
    <Loading @loaded="loaded = true" />
  </template>
  <template v-else>
    <Tip />
    <Cutscene v-if="state.phase == 'INTRO'" />
    <Interstitial v-if="state.phase == 'INTERSTITIAL'" />
    <Planning v-if="state.phase == 'PLANNING'" />
    <Stream v-else-if="state.phase == 'EVENTS'" />
    <Report v-else-if="state.phase == 'REPORT'" />
    <End :lose="true" v-else-if="state.phase == 'GAMEOVER'" />
    <End :lose="false" v-else-if="state.phase == 'GAMEWIN'" />
  </template>
</template>

<script>
import debug from '/src/debug';
import state from '/src/state';
import Tip from './tip/Tip.vue';
import Start from './Start.vue';
import Loading from './Loading.vue';
import End from './phases/End.vue';
import Cutscene from './phases/Cutscene.vue';
import Interstitial from './phases/Interstitial.vue';
import Report from './phases/Report.vue';
import Stream from './phases/events/Events.vue';
import Planning from './phases/planning/Planning.vue';
import AudioManager from '/src/audio/manager';

// Hacky
window.audioManager = new AudioManager();
if (!state.sound) {
  window.audioManager.muted = true;
}

export default {
  data() {
    return {
      state,
      started: false,
      loaded: false,
    };
  },
  methods: {
    start() {
      this.started = true;
    }
  },
  components: {
    Tip,
    Start,
    Report,
    Stream,
    Planning,
    End,
    Loading,
    Cutscene,
    Interstitial,
  },
}
</script>

After thorough analysis, it appears that all variables are indeed properly initialized. Interestingly, this error seems to exclusively manifest on Safari (both mobile and desktop). At this point, I'm uncertain if this issue is Vue-related or stems from another source. My Vue version is 3.1.4.

Answer №1

In my situation, I encountered an error when assigning the output of createApp to an exported variable and then importing and using it in another .ts file.

To work around this issue, you can try the following:

import { vueApp } from "./main";
const getVueApp = () => ((window as any).app as typeof vueApp);

After you have created your app as shown below:

const app = createApp(App);
(window as any).app = app;

You should be able to call something like getVueApp().$nextTick without any problems.

If you are not using TypeScript, you can directly reference window.app, the import and function wrapper are only to ensure proper type inference!

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

Retrieve the encrypted URL

I'm facing an issue with extracting parameters from an encrypted URL. When using the queryparams function, it only retrieves a portion of the URL after being decrypted. For instance, consider this example URL: http://localhost:4200/househouse? MGRjYjQ ...

Pulling the month name based on a specific year and week using Javascript

In my HTML form, there are two fields called Year and Week. When the user chooses a Year and Week from the dropdowns, I would like to show the corresponding Month Name for that specific year and week. Is there anyone who can assist me in retrieving the m ...

JavaScript Equivalent to C#'s BinaryReader.ReadString() Function

Currently, I am in the process of translating C# code into JavaScript. While transferring multiple datatypes from this file to matching functionalities found in various JavaScript libraries was relatively smooth, there is one specific function that seems t ...

The paragraph text should dynamically update upon clicking a button based on JavaScript code, however, the text remains unchanged despite attempts to modify it

I recently started learning JavaScript and wanted to update the content of a paragraph when a button is clicked. However, I encountered an issue where this functionality doesn't seem to work. <body> <p id="paragraph">Change Text on cl ...

Ensuring Package Security in NodeJS and NPM

Given the immense popularity of NodeJS and how NPM operates, what measures can be taken to prevent the installation of insecure or malware-laden packages? Relying solely on user feedback from sources like StackOverflow or personal blogs seems to leave a si ...

What is the purpose of the .Class method in ng.core.component within ES5?

ng.core.Component({ selector:'myapp', template:'<h1>Hello World</h1>' }). Class( { constructor:function() } ); ...

The Ionic tab is already finished displaying even before the data has completed loading

Creating a favorites section for a vouchers app has proven to be slightly challenging. When attempting to retrieve the current user's favorite vouchers and display them using ngFor in the HTML, I encountered an issue. The very first time I open the fa ...

Nuxt - displaying HTML exclusively on the server side

One issue I am facing is that my page includes a header sourced from a file on the server: data() { return { headerHTML: '' }; }, fetch() { this.headerHTML = fs.readFileSync('./header.html', 'utf8'); } To display th ...

"Resolving the problem of populating an empty array with JSON

My JSON structure at the top level is set up like this: { "video": [], "messages": [], "notifications": [] } In the database output stored in a variable called "result," I have data that I want to add to the "vide ...

Troubleshooting guide for resolving parse error when installing Open MCT

Hi there! I'm currently in the process of installing NASA's Open MCT (Link) but have hit a roadblock with errors during installation. Upon running npm install, I encountered the following error message: { Error: Parse error using esprima for fil ...

Click event triggers nested bootstrap collapse

As a beginner in bootstraps and coding, I am currently experimenting with opening the main bootstrap panel using an onclick event that includes nested sub panels. Here is my index.html file containing the panels and the button; <link href="https://m ...

Reorganize the placement of table columns between different rows

I am currently using a software program that automatically generates a form based on the selected options. The code for this form is generated in tables, which I am unable to directly edit. However, I would like to have the Amount, radio buttons, and their ...

"Exploring the possibilities of Ajax in conjunction with Sol

I recently completed a tutorial on Ajax Solr and followed the instructions in step one. Below is the code I wrote: header.php: <script type="text/javascript" src="static/js/ajax-solr/core/Core.js"></script> <script type="text/javascript" s ...

Using JQuery to rebind() after resetting the count

In my game, I have implemented a feature to ensure that the start button can only be clicked once each time it appears in order to prevent the function from loading multiple times. I wrote some code that tracks the number of clicks and unbinds the click e ...

Extracting multiline value from a textarea using JavaScript

I'm trying to extract a multiline value from a textarea using JavaScript or jQuery and store it in a cookie. Below is the code snippet I am using: HTML: <textarea id="cont" cols="72" rows="15"> JavaScript: var txt = $('#cont').val( ...

Tips for implementing the JSON object table filter functionality

My website features a collection of json objects organized as shown below: [ { "a": true or false, "b": "information", "c": "information", "d": "information", "e": "information" }, ... ] The goal here ...

Dynamic row additions causing vanishing rows in the table due to JS/jQuery implementation

I am currently facing an issue while trying to create a table where I can add rows dynamically. Despite looking at various solutions on this topic, none of them seem to resolve the problem I am encountering. The newly added rows disappear immediately after ...

What is the name of the event triggered when a jQuery UI draggable element is reverting back to its original position?

I am currently using jQuery UI to create a draggable element on my website. I have added a function to the drag event that continuously tracks the position of the element while the user is dragging it. Additionally, I have set revert: true on this element ...

Creating connections between variables and elements in nested ngRepeats in Angular

I've been facing a challenge with my app where I need to update the comments section whenever a comment is added, edited, or deleted without having to refresh the page. I am using ngResource to handle queries for both articles and comments (e.g. $scop ...

Tips for streamlining the transfer of essential features from a main project to its duplicate projects

In my Angular project, I have a core repository on GitHub that serves as the foundation for custom client projects. Each time a new client comes onboard, we create a clone of the core project and make customizations based on their requirements. The issue ...