Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Exporting Class with Require yields error

There is a nuance that I seem to be missing. I have Googled so many fixes recommended for this problem I don’t know what is real anymore, nothing seems to work.

MyProject on Replit and the offending class I am trying to export.

I keep getting the same error. I have commented out other changes I have tried in my effort. I want to cut the Gordian knot and just paste the ReplitDB class into my MoodDB class, but I also want to understand what I am missing here.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Offending lines:

ReplitDB.js – Method A

...
exports.module = ReplitDB;

ReplitDB.js – Method B

modules.export = ReplitDB ;

returns:

ReferenceError: modules is not defined
    at Object.<anonymous> (/home/runner/Class-Extends-Error/libs/ReplitDB.js:110:1)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/runner/Class-Extends-Error/libs/MoodDB.js:23:18)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)

MoodDB.js:

const ReplitDB = require('./ReplitDB.js')

class MoodDB extends ReplitDB {
    constructor(){
        super()
    }
    
    ...
}

Error:

TypeError: Class extends value #<Object> is not a constructor or null
    at Object.<anonymous> (/home/runner/Class-Extends-Error/libs/MoodDB.js:7:22)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/runner/Class-Extends-Error/index.js:12:16)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)

>Solution :

There is a mistake in your export. It should be

module.exports = ReplitDB;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading