【问题标题】:TypeError: Class extends value undefined is not a constructor or null - Node.jsTypeError: Class extends value undefined is not a constructor or null - Node.js
【发布时间】:2020-08-27 12:31:07
【问题描述】:

我尝试在index.js 中使用 Clear,但代码不起作用,它通过 Moderation 扩展了 Clear 类以获取 Moderation 方法。

完全错误:

class Clear extends Moderation {
                    ^
TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (C:\Users\Chigu\SoftKr\Asuha-Discord-Universal-Bot\Src\Actions\Moderation\Commands\Clear.js:5:21)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\Users\Chigu\SoftKr\Asuha-Discord-Universal-Bot\Src\Actions\Moderation\Moderation.js:2:17)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)

Process finished with exit code 1

Clear.js

const Discord = require("discord.js");
const {Moderation} = require("../Moderation");

class Clear extends Moderation {
    constructor(message, client) {
        super(message, client);
        this.command = "clear";
   } //methode and code
}

module.exports = {
    Clear
}

Moderation.js

const {Clear} = require("./Commands/Clear");

class Moderation {
    constructor(message, client, staff, prefix) {
        this.message = message;
        this.client = client;
        this.staff = staff;
        this.prefix = prefix;
    } //methode and code
}

module.exports = {
    Moderation,
}

【问题讨论】:

    标签: javascript node.js class discord.js extends


    【解决方案1】:

    会不会是循环依赖问题?您正在将每个类导入另一个类。您是否尝试从Moderation.js 中删除此行?

    const {Clear} = require("./Commands/Clear");
    

    【讨论】:

    • 是的,非常感谢你这是一个循环依赖!
    猜你喜欢
    • 2018-07-14
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 2022-12-02
    • 2021-11-02
    • 2022-12-20
    • 2017-08-27
    相关资源
    最近更新 更多