简体   繁体   English

未捕获的类型错误:类扩展值 #<Object> 不是构造函数或 null

[英]Uncaught TypeError: Class extends value #<Object> is not a constructor or null

My code works with all the other modules but JBehaviour is giving me this problem and idk what im doing wrong because it seems like I did everything right我的代码适用于所有其他模块,但 JBehaviour 给了我这个问题,并指出我做错了什么,因为看起来我做的一切都是正确的

Full Error: Uncaught TypeError: Class extends value # is not a constructor or null at Object.完整错误:未捕获的类型错误:类扩展值 # 不是构造函数或 Object 处的 null。 (C:\\Users\\etern\\Documents\\GameEngine\\src\\engine\\classes\\JBehaviour.js:3) at Object. (C:\\Users\\etern\\Documents\\GameEngine\\src\\engine\\classes\\JBehaviour.js:3) 在对象。 (C:\\Users\\etern\\Documents\\GameEngine\\src\\engine\\classes\\JBehaviour.js:11) (C:\\Users\\etern\\Documents\\GameEngine\\src\\engine\\classes\\JBehaviour.js:11)

test_game.js test_game.js

const {Vector2, GameObject, Rigidbody2d, JBehaviour, Input} = require('./Core')

Core.js核心.js

//Structs
const Vector2 = require('./structs/Vector2')

//Classes
const GameObject = require('./classes/GameObject')
const Rigidbody2d = require('./classes/Rigidbody2d')
const JBehaviour = require('./classes/JBehaviour')
const Input = require('./classes/Input')


module.exports = {Vector2, GameObject, Rigidbody2d, JBehaviour, Input}

JBehaviour.js JBehaviour.js

    const Behaviour = require('./Behaviour')

class JBehaviour extends Behaviour{
    constructor(){
        super('JBehaviour')
    }
}


module.exports = JBehaviour

Behaviour.js Behaviour.js

const Component = require('./Component')

class Behaviour extends Component{
    constructor(name){
        super(name)
        this.enabled = true
    }
}

Component.js组件.js

const OBJ = require('./Object')
class Component extends OBJ {
    constructor(name){
        super(name)
        this.gameObject = null
        this.tag = null
        this.transform = null
    }

    AssignGameObject(gameObject){
        this.gameObject = gameObject
        this.tag = gameObject.tag
        this.transform = gameObject.transform
    }

    CompareTag(tag){

        return (this.tag === tag)
    }
}

module.exports = Component

Object.js对象.js

class OBJ{
    constructor(name){
        this.name = name
    }

    static Destroy(object){
        delete object.name
    }

    static Instantiate(original){

        return new OBJ(original.name)
    }

    ToString(){

        return toString(this.name)
    }
}

module.exports = OBJ

You didn't export Behaviour , so the value returned by require('./Behaviour') is an empty object.您没有导出Behaviour ,因此require('./Behaviour')返回的值是一个空对象。 Empty objects can't be extended from.不能扩展空对象。

Export Behaviour like you do with JBehaviour :像使用JBehaviour一样导出Behaviour

module.exports = Behaviour

未捕获的类型错误:Class 扩展值 #<object> 不是构造函数或 null - 使用 superagent-throttle <div id="text_translate"><div><aside class="s-notice s-notice__info post-notice js-post-notice mb16 js-bounty-notification" role="status"><div class="d-flex fd-column fw-nowrap"><div class="d-flex fw-nowrap"><div class="flex--item mr8"><svg aria-hidden="true" class="svg-icon iconClock" width="18" height="18" viewbox="0 0 18 18"><path d="M9 17c-4.36 0-8-3.64-8-8 0-4.36 3.64-8 8-8 4.36 0 8 3.64 8 8 0 4.36-3.64 8-8 8Zm0-2c3.27 0 6-2.73 6-6s-2.73-6-6-6-6 2.73-6 6 2.73 6 6 6ZM8 5h1.01L9 9.36l3.22 2.1-.6.93L8 10V5Z" /></svg></div><div class="flex--item wmn0 fl1 lh-lg"><div class="flex--item fl1 lh-lg"> <a href="https://stackoverflow.com/help/bounty" rel="nofollow noreferrer">赏金</a>将<span title="2022-02-13 21:51:46Z">在 6 天后</span>到期。 此问题的答案有资格获得<span class="s-badge__bounty d-inline px4 py2 ba bc-transparent bar-sm fs-caption va-middle">+300</span>声望赏金。 <a href="/users/299472/steve-moseley" rel="nofollow noreferrer">Steve Moseley</a>想引起对这个问题的更多关注:<blockquote><div> 我有一个需要限制并发请求的应用程序 - superagent-throttle 是我知道的唯一选项,我没有足够的 JavaScript/TypeScript/Vite 知识来自己解决这个问题 - 请帮助!</div></blockquote></div></div></div></div></aside></div><p> 我正在尝试在我的TypeScript项目中导入 npm package superagent-throttle,但是当我这样做时,我会收到以下消息:</p><p> Uncaught TypeError: Class extends value #&lt;Object&gt; is not a constructor or null</p><p> 如果我使用require它可以正常工作:</p><p> const Throttle = require("superagent-throttle");</p><p> 但是,我已经开始使用不允许require的Vite ,所以我必须使用import来代替。</p><p> 我引用它的代码想要实例化一个class即:</p><pre> this.throttle = new Throttle({ // set false to pause queue active: true, // how many requests can be sent every `ratePer` rate: 10000, // number of ms in which `rate` requests may be sent ratePer: 1000, // How many requests can be sent concurrently concurrent: 2 });</pre><p> 我尝试了import语句的不同变体,但这些都不适合我:</p><pre> import { Throttle } from "superagent-throttle"; import Throttle from "superagent-throttle"; import * as Throttle from "superagent-throttle";</pre><p> 它们都给出相同的结果 - 它们编译正常,但在运行时失败并显示相同的错误消息(如上)。</p><p> superagent-throttle JS 文件中的代码看起来相当晦涩,我不知道它在做什么,所以我正在努力尝试了解如何解决这个问题:</p><p> package 文件: node_modules/superagent-throttle/dist/index.js :</p><pre> 'use strict'; var _events = require('events'); var _events2 = _interopRequireDefault(_events); function _interopRequireDefault(obj) { return obj &amp;&amp; obj.__esModule? obj: { default: obj }; }. . . class Throttle extends _events2.default { constructor(options) { super(); // instance properties this._options({ _requestTimes: [0], _current: 0, _buffer: [], _serials: {}, _timeout: false }); . . . etc. . .</pre><p> 任何帮助表示赞赏!</p></div></object> - Uncaught TypeError: Class extends value #<Object> is not a constructor or null - with superagent-throttle

类型错误:Class 扩展值 #<object> 不是反应js中的构造函数或null<div id="text_translate"><p> 我试图超越一些主要反应按钮组件的 function,但是在扩展主要反应按钮组件 class 时出现此错误。 这是我的代码:</p><pre> import { Button } from "primereact/button"; class BtnBox extends Button { constructor(props) { super(props); this.renderLabel = this.renderLabel.bind(this); } renderLabel() { return &lt;span&gt;icon&lt;/span&gt;; } } class IconButton extends React.Component { render() { return ( &lt;div className="icon-button"&gt; &lt;BtnBox {...this.props} /&gt; &lt;/div&gt; ); } } export default IconButton;</pre></div></object> - TypeError: Class extends value #<Object> is not a constructor or null in react js

“类扩展价值#<object> 不是构造函数或 null"<div id="text_translate"><p> 感谢阅读我的帖子 我的代码出现了这个错误:“Class extends value # is not a constructor or null” 这是我的代码,我正在尝试导出/导入类。</p><p> 怪物.js:</p><pre> const miniMonster = require("./minimonster.js"); class monster { constructor(options = { name }, health) { this.options = options; this.health = 100; this.heal = () => { return (this.health += 10); }; } } let bigMonster = new monster("Godzilla"); console.log(bigMonster); console.log(bigMonster.heal()); let mini = new miniMonster("Demon"); console.log(mini); console.log(mini.heal()); module.exports = monster;</pre><p> 迷你怪物.js:</p><pre> const monster = require("./monster.js"); class miniMonster extends monster { constructor(options) { super(options); this.health = 50; this.heal = () => { return (this.health += 5); }; } } let miniM = new miniMonster("Jon"); console.log(miniM); module.exports = miniMonster;</pre><p> 感谢您提供的任何帮助,</p><p> 祝你有美好的一天</p></div></object> - "Class extends value #<Object> is not a constructor or null"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Nodemailer:未捕获类型错误:Class 扩展值未定义不是构造函数或 null - Nodemailer: Uncaught TypeError: Class extends value undefined is not a constructor or null 如何解决 Uncaught TypeError: Class extends value undefined is not a constructor or null? - How to solve Uncaught TypeError: Class extends value undefined is not a constructor or null? 未捕获的类型错误:Class 扩展值 #<object> 不是构造函数或 null - 使用 superagent-throttle <div id="text_translate"><div><aside class="s-notice s-notice__info post-notice js-post-notice mb16 js-bounty-notification" role="status"><div class="d-flex fd-column fw-nowrap"><div class="d-flex fw-nowrap"><div class="flex--item mr8"><svg aria-hidden="true" class="svg-icon iconClock" width="18" height="18" viewbox="0 0 18 18"><path d="M9 17c-4.36 0-8-3.64-8-8 0-4.36 3.64-8 8-8 4.36 0 8 3.64 8 8 0 4.36-3.64 8-8 8Zm0-2c3.27 0 6-2.73 6-6s-2.73-6-6-6-6 2.73-6 6 2.73 6 6 6ZM8 5h1.01L9 9.36l3.22 2.1-.6.93L8 10V5Z" /></svg></div><div class="flex--item wmn0 fl1 lh-lg"><div class="flex--item fl1 lh-lg"> <a href="https://stackoverflow.com/help/bounty" rel="nofollow noreferrer">赏金</a>将<span title="2022-02-13 21:51:46Z">在 6 天后</span>到期。 此问题的答案有资格获得<span class="s-badge__bounty d-inline px4 py2 ba bc-transparent bar-sm fs-caption va-middle">+300</span>声望赏金。 <a href="/users/299472/steve-moseley" rel="nofollow noreferrer">Steve Moseley</a>想引起对这个问题的更多关注:<blockquote><div> 我有一个需要限制并发请求的应用程序 - superagent-throttle 是我知道的唯一选项,我没有足够的 JavaScript/TypeScript/Vite 知识来自己解决这个问题 - 请帮助!</div></blockquote></div></div></div></div></aside></div><p> 我正在尝试在我的TypeScript项目中导入 npm package superagent-throttle,但是当我这样做时,我会收到以下消息:</p><p> Uncaught TypeError: Class extends value #&lt;Object&gt; is not a constructor or null</p><p> 如果我使用require它可以正常工作:</p><p> const Throttle = require("superagent-throttle");</p><p> 但是,我已经开始使用不允许require的Vite ,所以我必须使用import来代替。</p><p> 我引用它的代码想要实例化一个class即:</p><pre> this.throttle = new Throttle({ // set false to pause queue active: true, // how many requests can be sent every `ratePer` rate: 10000, // number of ms in which `rate` requests may be sent ratePer: 1000, // How many requests can be sent concurrently concurrent: 2 });</pre><p> 我尝试了import语句的不同变体,但这些都不适合我:</p><pre> import { Throttle } from "superagent-throttle"; import Throttle from "superagent-throttle"; import * as Throttle from "superagent-throttle";</pre><p> 它们都给出相同的结果 - 它们编译正常,但在运行时失败并显示相同的错误消息(如上)。</p><p> superagent-throttle JS 文件中的代码看起来相当晦涩,我不知道它在做什么,所以我正在努力尝试了解如何解决这个问题:</p><p> package 文件: node_modules/superagent-throttle/dist/index.js :</p><pre> 'use strict'; var _events = require('events'); var _events2 = _interopRequireDefault(_events); function _interopRequireDefault(obj) { return obj &amp;&amp; obj.__esModule? obj: { default: obj }; }. . . class Throttle extends _events2.default { constructor(options) { super(); // instance properties this._options({ _requestTimes: [0], _current: 0, _buffer: [], _serials: {}, _timeout: false }); . . . etc. . .</pre><p> 任何帮助表示赞赏!</p></div></object> - Uncaught TypeError: Class extends value #<Object> is not a constructor or null - with superagent-throttle 类型错误:Class 扩展值 #<object> 不是反应js中的构造函数或null<div id="text_translate"><p> 我试图超越一些主要反应按钮组件的 function,但是在扩展主要反应按钮组件 class 时出现此错误。 这是我的代码:</p><pre> import { Button } from "primereact/button"; class BtnBox extends Button { constructor(props) { super(props); this.renderLabel = this.renderLabel.bind(this); } renderLabel() { return &lt;span&gt;icon&lt;/span&gt;; } } class IconButton extends React.Component { render() { return ( &lt;div className="icon-button"&gt; &lt;BtnBox {...this.props} /&gt; &lt;/div&gt; ); } } export default IconButton;</pre></div></object> - TypeError: Class extends value #<Object> is not a constructor or null in react js WebdriverIO自定义报告程序-TypeError:类扩展值# <Object> 不是构造函数或null - WebdriverIO Custom Reporter - TypeError: Class extends value #<Object> is not a constructor or null 类型错误:Class 扩展值 #<basepage> 不是构造函数或 null</basepage> - TypeError: Class extends value #<BasePage> is not a constructor or null 类型错误:Class 扩展值 #<datarepository> 不是构造函数或 null</datarepository> - TypeError: Class extends value #<DataRepository> is not a constructor or null TypeError: Class extends value undefined is not a constructor 或 null - TypeError: Class extends value undefined is not a constructor or null 'Uncaught TypeError: Class extends value undefined is not a constructor or null' 尝试加载外部 TypeScript 组件时 - 'Uncaught TypeError: Class extends value undefined is not a constructor or null' when trying to load external TypeScript component “类扩展价值#<object> 不是构造函数或 null"<div id="text_translate"><p> 感谢阅读我的帖子 我的代码出现了这个错误:“Class extends value # is not a constructor or null” 这是我的代码,我正在尝试导出/导入类。</p><p> 怪物.js:</p><pre> const miniMonster = require("./minimonster.js"); class monster { constructor(options = { name }, health) { this.options = options; this.health = 100; this.heal = () => { return (this.health += 10); }; } } let bigMonster = new monster("Godzilla"); console.log(bigMonster); console.log(bigMonster.heal()); let mini = new miniMonster("Demon"); console.log(mini); console.log(mini.heal()); module.exports = monster;</pre><p> 迷你怪物.js:</p><pre> const monster = require("./monster.js"); class miniMonster extends monster { constructor(options) { super(options); this.health = 50; this.heal = () => { return (this.health += 5); }; } } let miniM = new miniMonster("Jon"); console.log(miniM); module.exports = miniMonster;</pre><p> 感谢您提供的任何帮助,</p><p> 祝你有美好的一天</p></div></object> - "Class extends value #<Object> is not a constructor or null"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM