Esoteric error in production: `Type Error: e is undefined`
Esoteric error in production: `Type Error: e is undefined`
我正在将我的 Vue 应用程序发布到生产环境中,但是一个特定的组件抛出了一条我无法追踪的深奥错误消息,因为所有项目文件都已捆绑并且变量名称已更改。这个错误也只能在生产模式(构建)中重现,让我相信这是一个与捆绑本身相关的问题。
重现步骤
正如我之前提到的,该问题仅出现在生产模式中。因此,我已尽最大努力通过简单地在 Netlify 上发布该应用程序来重现该问题。以下是步骤:
- 在此处访问 netlify 上的应用程序:https://grandquest.netlify.com
- 向下滚动到 "Sign up" 表单并创建一个假帐户来测试错误
- 在登录页面使用这些凭据登录
- 打开控制台
- 访问 world 并单击显示 "Explore Monokai"
的按钮
这样做应该会将您带到错误的 route/component (grandquest.netlify.com/map)
详情
该应用程序在开发模式下运行良好,但是(正如我将 link 所做的那样),当 运行 在生产模式下时,该应用程序会产生错误:Type Error : 当我挂载特定路由时,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.
显示为 'bundled' 的变量
由于这个错误的性质(我不确定代码中的变量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();
}
}
@/game/places/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 上)
对于此问题,我们将不胜感激 :)
有这个功能吗?
v-on:resize="resizeMonitor"
我没有在任何地方看到它。我想如果函数不存在你会得到这种类型的错误
我正在将我的 Vue 应用程序发布到生产环境中,但是一个特定的组件抛出了一条我无法追踪的深奥错误消息,因为所有项目文件都已捆绑并且变量名称已更改。这个错误也只能在生产模式(构建)中重现,让我相信这是一个与捆绑本身相关的问题。
重现步骤
正如我之前提到的,该问题仅出现在生产模式中。因此,我已尽最大努力通过简单地在 Netlify 上发布该应用程序来重现该问题。以下是步骤:
- 在此处访问 netlify 上的应用程序:https://grandquest.netlify.com
- 向下滚动到 "Sign up" 表单并创建一个假帐户来测试错误
- 在登录页面使用这些凭据登录
- 打开控制台
- 访问 world 并单击显示 "Explore Monokai" 的按钮
这样做应该会将您带到错误的 route/component (grandquest.netlify.com/map)
详情
该应用程序在开发模式下运行良好,但是(正如我将 link 所做的那样),当 运行 在生产模式下时,该应用程序会产生错误:Type Error : 当我挂载特定路由时,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();
}
}
@/game/places/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 上)
对于此问题,我们将不胜感激 :)
有这个功能吗?
v-on:resize="resizeMonitor"
我没有在任何地方看到它。我想如果函数不存在你会得到这种类型的错误