参考错误:在初始化之前无法访问“选项”,但“选项”在使用前已初始化

此时我真的一无所知,并已尝试查找我能想到的所有内容,但我的代码出现此错误:

ReferenceError: Cannot access 'options' before initialization
at file:///D:/node mods/agda.js/src/constants/Constants.js:4:45

常量.js

import { options } from "../ws/WebSocketManager.js";

export const Constants = {
    GATEWAY: `wss://gateway.discord.gg/?v=${options.gateway_version}&encoding=json`
}

WebSocketManager.js(只显示一个片段)

import WebSocket from 'ws';
import { Constants } from '../constants/Constants.js';
import { OPCodes } from '../constants/OPCodes.js';
import { Heartbeat,Identify } from '../constants/Payloads.js';

export const options = {
    debugMode: true,debugMode_payloads: true,debugMode_connection: true,debugMode_heartbeats: true,useOS: 'linux',intents: 513,gateway_version: '9'
}
gjlgjlgjlgjl 回答:参考错误:在初始化之前无法访问“选项”,但“选项”在使用前已初始化

我已经修复了它,但采用了一种不同的方法。

对于那些可能需要它的人,

export const Gateway = {
    URL: undefined,VERSION: 9
}

Gateway.URL = `wss://gateway.discord.gg/?v=${Gateway.VERSION}&encoding=json`;
本文链接:https://www.f2er.com/7365.html

大家都在问