生产中的深奥错误:`类型错误:e未定义`

问题描述 投票:0回答:1

我正在将我的Vue应用程序发布到生产环境中,但是一个特定组件会抛出一条我无法跟踪的深奥错误消息,因为所有项目文件都已捆绑在一起并且变量名称已更改。此错误也只能在生产模式(构建)中重现,这使我相信这是与捆绑本身相关的问题。

重现步骤

正如我之前提到的,问题仅存在于生产模式中。因此,我已经尽力通过简单地在Netlify上发布应用程序来重现该问题。以下是步骤:

  • 访问netlify上的应用程序:https://grandquest.netlify.com
  • 向下滚动到“注册”表单并创建一个虚假帐户来测试该错误
  • 在登录页面使用这些凭据登录
  • 打开控制台
  • 访问world,然后单击“Explore Monokai”按钮

这样做会带你到错误的路线/组件(grandquest.netlify.com/map)

细节

  • 该应用程序在开发模式下工作得很好,但是(我将链接到),在生产模式下运行时,应用程序会产生错误:类型错误:当我挂载特定路径时,e未定义(仅限Mozilla Firefox,AFAIK)。
  • 其次,在vue-cli构建日志中,我可以看到与文件大小限制相关的各种警告。以下是构建日志中的警告:
    warning  

    asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
    This can impact web performance.
    Assets: 
    img/gold-frame.536f6ce1.png (415 KiB)
    media/combat-fail.f73de150.mp3 (317 KiB)
    img/monokai-village.84e00e29.png (1.25 MiB)
    img/combat.835c3bee.png (1.04 MiB)
    img/combat-shop.138daeea.png (1.56 MiB)
    img/potions-shop.dea509b2.png (2.07 MiB)
    media/fields-music1.bd10f1d6.mp3 (2.46 MiB)
    img/village-gate.f8c4cfd2.png (3.52 MiB)
    js/chunk-vendors.6c22f97f.js (1.71 MiB)

    warning  

    entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
    Entrypoints:
    app (1.95 MiB)
    js/chunk-vendors.6c22f97f.js
    css/app.fa9c625b.css
    js/app.9440af5a.js


    warning  

    webpack performance recommendations: 
    You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
    For more info visit https://webpack.js.org/guides/code-splitting/

    DONE  Build complete. The dist directory is ready to be deployed.
    INFO  Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html

    ✨ Done in 122.97s.

这两个细节让我相信这个问题是由捆绑错误引起的

-

我试过在我的代码中寻找任何变量名称e,想想也许这是一个事件,但我的代码中没有这样的变量。它似乎是一个由vue“捆绑”的变量。

由于此错误的性质(我不确定变量e在代码中是什么,因为它被混淆了),我已尽力总结Map组件的相关代码。我也不介意共享整个文件,如果它可以帮助,但是,没有找到e变量。

@ / views / Map.vue

<template>
<div>
    <!-- LOADING SCREEN -->
    <div v-if="!gameInterface.gameInitialized" id="loading-screen">
      <img src="@/assets/img.png" v-on:click="$router.push(`/world`)">
      <div class="tip">Fun fact</div>
      <div class="loading-text">Loading assets</div>
    </div>
    <!-- MAP CONTAINER -->
    <div class="map">
      <button class="exit-button" v-on:click="() => $router.replace({ name: 'world' })">
    EXIT
      </button>
      <!-- CANVAS PARENT -->
      <div
        id="canvas-parent"
        v-on:mousemove="gameInterface.mouseMonitor"
        v-on:mouseleave="gameInterface.pointer.hovering = false"
        v-on:resize="resizeMonitor"
      />
      <!-- RENDER THE SHOP -->
      <Shop v-if="gameInterface.chosenShop"/>
    </div>
</div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { State, Mutation } from 'vuex-class'
// typescript types
import { User } from '@/types';
// vue components
import Shop from '@/components/Shop.vue';
// the game controller
import gameInterface from '@/game/places/map.ts';

@Component({
  components: { Shop }
})
export default class Map extends Vue {
  @State public user!: User;

  public gameInterface = gameInterface();

  public mounted() {
    if (!this.user.authenticated) {
      return this.$router.replace({ name: 'world' });
    }
    this.gameInterface.launch();
    document.addEventListener('wheel', this.gameInterface.scrollMonitor, true);
  }
  public destroyed() {
    document.removeEventListener('wheel', this.gameInterface.scrollMonitor, true);
    this.gameInterface.destroyGame();
  }
}

@ /游戏/地区/ map.ts

export default () => {
let game: any = null;

let global = {
  tooltip: {},
  chosenShop: null,
  gameInitialized: false,
  pointer: { x: 0, y: 0, hovering: false },
  launch() {
    if (!game) {
      // here a phaser game is started
      game = new Phaser.Game({
        // ...config here
        created() {
          global.gameInitialized = true;
        },
      });
    }
  },
  destroyGame() {
    if (game) {
      game.destroy();
    }
  },
  mouseMonitor(event) {
    if (!global.gameInitialized) {
      return;
    }

    global.pointer = {
      x: event.clientX,
      y: event.clientY,
      hovering: true,
    };
  },
  scrollMonitor(event) {
    if (!game) {
      return;
    }
    if (event.deltaY < 0 && game.scene.scenes[0].cameras.main.zoom < 2) {
      game.camera.zoom += 0.1;
    }
    if (event.deltaY > 0 && game.scene.scenes[0].cameras.main.zoom > 1.15) {
      game.camera.zoom -= 0.1;
    }
  },
  exitShop() {
    if (!game) {
      return;
    }
    global.chosenShop = null;
    game.resume();
  }
};

return global;
};

预期产出

您应该在资产加载时看到加载屏幕一段时间,然后屏幕上会出现一个地图。您可以使用光标上下导航此地图,也可以单击各个商店。

实际输出

屏幕似乎无限期加载,因为发生了已停止应用程序的错误。该错误现在应该出现在控制台中,读取类型错误:e未定义(在Firefox上)

任何和所有的帮助都受到这个问题的赞赏:)

javascript typescript vue.js vue-cli
1个回答
1
投票

这个功能存在吗?

v-on:resize="resizeMonitor"

我没有在任何地方看到它。我想如果函数不存在,你会得到这种类型的错误

© www.soinside.com 2019 - 2024. All rights reserved.