- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我一直在 Nodejs 上使用 ES6 风格的语法和 ESM 模块加载器进行导入/导出。一切都很好,直到我开始收到与导入有关的错误。
错误消息如下:
joseph@InsaneMachine:~/placeholder2/main-server$ npm start
> main-server@1.0.0 start /home/joseph/placeholder2/main-server
> nodemon --experimental-modules src/index.mjs
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node --experimental-modules src/index.mjs`
(node:16942) ExperimentalWarning: The ESM module loader is experimental.
file:///home/joseph/placeholder2/main-server/src/games/game-player.mjs:3
export default class GamePlayer extends Player
^
ReferenceError: Cannot access 'Player' before initialization
at file:///home/joseph/placeholder2/main-server/src/games/game-player.mjs:3:41
at ModuleJob.run (internal/modules/esm/module_job.js:109:37)
at async Loader.import (internal/modules/esm/loader.js:132:24)
[nodemon] app crashed - waiting for file changes before starting...
以下是 Player 文件(基类):
import PasswordHash from 'password-hash';
import GamesService from '../games/games.service.mjs';
import PlayersService from './players.service.mjs';
import QueueingService from '../queueing/queueing.service.mjs';
export default class Player
{
constructor(object)
{
Object.assign(this, JSON.parse(JSON.stringify(object)));
}
get id()
{
return this._id.toString();
}
equals(other)
{
if(other.id != null)
return other.id == this.id;
return false;
}
checkPassword(password)
{
return PasswordHash.verify(password, this.password);
}
online()
{
return PlayersService.consumer.isPlayerOnline(this);
}
inQueue()
{
return QueueingService.queued(this);
}
inGame()
{
return GamesService.getActiveGameByPlayer(this) != null;
}
reduce()
{
return {
id: this.id,
username: this.username,
email: this.email,
admin: this.admin,
online: this.online(),
in_queue: this.inQueue(),
in_game: this.inGame(),
};
}
static hashPassword(password)
{
return PasswordHash.generate(password);
}
static schema = {
username: String,
password: String,
email: String,
email_confirmed: Boolean,
admin: Boolean,
}
}
和游戏玩家(子类):
import Player from '../players/player.mjs';
export default class GamePlayer extends Player
{
constructor(player, token)
{
super(player);
this.token = token;
}
}
以及项目的层次结构:
src/
-- games/
-- -- game-player.mjs
-- -- ...
players/
-- -- player.mjs
-- -- ...
-- ...
除非是其他原因,否则我该如何解决此导入问题?
编辑:据我所知,我没有使用 Babel,我正在使用 Node.js 提供的 --external-modules。不确定这是如何工作的。
最佳答案
我去了 Node.JS 论坛并询问可能是什么问题。根本不是 babel 问题,只是循环依赖。例如:
// A.js
import B from './B.js'
export default class A{}
// B.js
import A from './A.js'
export default class B extends A{}
抱歉,没有足够的信息来解决这个问题。我在 node.js github 上得到了很多帮助,有人在 github 上查看了我的项目,最终找到了一个两个模块相互指向的实例。
关于javascript - 引用错误: Cannot access 'Player' before initialization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60122727/
class Skeleton { public: void attack(Player player) { if (canAttackSkeleton()) {
我是使用 Java 播放音频的新手。我编写了代码来播放一些广播流。 我发现有一些流媒体网址,例如 http://fm939.wnyc.org/wnycfm .这没有端口号并包含斜杠。我只能使用 jav
我在我的 ReactPlayer 组件中使用 light={true} 设置在视频列表中显示缩略图。这在初始加载时工作正常。但是,当用户单击缩略图时,我会打开一个模式来播放视频(在单独的 ReactP
所以我目前正在为玩家重构游戏中的代码并启动一个玩家类: import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.b
某些应用程序和 IDE 建议安装 Adobe Flash 播放器的调试版本。我知道即使没有通过测试电影运行 Flash,这也允许查看跟踪语句,但还有什么不同呢?有什么事吗? 此外,我如何判断我看到
我已经阅读过类似的问题,但没有一个对我的情况有帮助。 这是我的 YouTube iframe: 我动态添加了 src 属性。 这是我的播放器: var player; function onYou
研究了许多主题和不同的领域后,我感到不知所措。我知道答案可能很简单,但我只是没有看到它。言归正传,这就是我正在做的事情。 我有一个本地托管的网页,当前如果在 Internet Explorer 中加载
Jwplayer 在正确加载视频之前闪烁“加载播放器时出错:无法加载播放器配置”一秒钟。我只是觉得这看起来不专业,我花了很多时间寻找如何抑制错误或隐藏它,直到视频加载完成。 在 Chrome 或 Sa
在 Exoplayer 版本中 2.14.1 Playerd.EventListener()已弃用。当我阅读文档时,它说使用而不是 Player.Listener ,但我不知道如何使用该方法,如下面的
我正在尝试创建一个按钮,允许用户单击它并停止嵌入的 YouTube 视频。但是,每当我尝试调用播放器对象本身来使用函数player.playVideo()时,我都会收到一条错误消息,指出该函数未定义。
我正在通过制作一个简单的纸牌游戏来学习数据结构。在这段代码中,我有一个类 Player 和一个包含游戏中所有玩家的 Queue。 队列的实现: template class Queue{
MPMoviePlayerController 播放器在按下完成按钮后永久隐藏播放器控件。 我有一个带有 moviePlayer.controlStyle = MPMovieControlStyleE
Player::Player(string Playername, int nr ,Board* x) { imie= Playername; number=nr; int k
情况是这样的。我在我的 Django REST API 上得到了一个列表:/playerslist/ 它返回了一个玩家列表,就像这个一样: http://pastebin.com/JYA39gHT 这
我有一个 YoutubePlayer 在我的 Motion Layout 中播放视频。我想实现这个youtube-like motion https://developer.android.com/t
我一直在使用 MPC-HC 窗口的状态文本来确定视频是正在播放还是暂停。但是,在全屏模式下或隐藏状态栏时,状态文本不会更新。有人向 MPC-HC 团队指出了这个错误,但尚未解决:https://tra
我的 Blackjack 默认构造函数中有这一行。 m_players[0].SetPlayerName("Jane"); 这在我的 Player 类中使用了一个 setter 来将玩家的名字设置为
我最近一直在开发 Ruby on Rails 应用程序。我们使用 Yahoo Web Player 来播放我们的音频和视频文件。它工作得非常好,特别是对于不允许使用 Flash 的平板电脑和智能手机。
更新:这个问题的前提被证明是被误导的。除非移动是响应用户单击,否则不会发生此问题。请参阅here . 这几天我一直在为一个错误而苦苦挣扎,希望有人能提供帮助。 我有一个 jquery 脚本,它使用 j
用图片说明更容易。抱歉审查。 在这个屏幕中有一个 WebView 是白色的部分,包含一个带有 Flash 内容的网页。 Flash 内容应该在底部红色条下方(部分隐藏在后面),因为 webview 边
我是一名优秀的程序员,十分优秀!