Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Why is index.bindClient is not a function?

Why is this not a function? Importing ./src/index.js in ./index.js works just fine, but trying to import it in ./src/Client.js just doesn't let me. It's not some "invalid file path" because I don't have any errors, and it autofilled in the require function.

Here is my code:

./index.js

const index = require("./src/index.js")
console.log(index) //logs the module

./src/Client.js

const index = require("./index.js") //I even tried require("../src/index.js") and the full path (D:/...)
console.log(index) //logs empty object

index.bindClient(client) //TypeError: index.bindClient is not a function

./src/index.js

module.exports = {
    Send,
    MessageDelete,
    Command,
    Client: C,
/**
 * 
 * @param {Client} client
 */
    bindClient(client) {
        c = client;
        return (
            c.on("messageCreate", msg => {
            const command = commands.find(c => msg.content.startsWith(c.name))
            if (command) {
                command.send ? Send(command.send, msg.channel) : null
                command.delete ? MessageDelete(msg) : null
                command.emit("execute", msg, command)
            }
        })
        );
    }
}

This is not my full code, I only included the important parts that relate to the error. I tried logging as much as I could and everything except for index in ./src/Client.js was what it was supposed to be. This error even happened when I tried to set it like module.exports.bindClient = ...

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As said by @Elitezen in their comment, the files were requiring each other. Putting the require at the bottom and calling the function directly from it worked

require("./index.js").bindClient(client)
about 4 years ago · Juan Pablo Isaza Report

0

You can destructure it...

const { Send, MessageDelete, Command, Client, bindClient } = require("./src/index.js")
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!