Encountered an issue with module 'C:\Users\***\Desktop\Bot\modules\data\MongoDB.js'. Error message: ExpectedValidationError > s.instance(V) was thrown

Issue with MongoDB Connection Setup

Error Message: Failed to resolve module 'C:\Users\luci\Desktop\Lunar Bot\modules\data\MongoDB.js': ExpectedValidationError > s.instance(V)

A TypeScript bot encountering errors when converting to JS on load.

import mongoose from "mongoose";

export class MongoConnection {
  public versions = "^7";
  public mongoose!: typeof mongoose;

  async onstart() {
    this.mongoose = await mongoose.connect(process.env.MONGODB!);

    if (this.mongoose) console.log("Connected to MongoDB Database");

    return true;
  }
}

export default new MongoConnection();

JS Code Conversion:

import mongoose from "mongoose";
export class MongoConnection {
    constructor() {
        this.versions = "^7";
    }
    async onstart() {
        this.mongoose = await mongoose.connect(process.env.MONGODB);
        if (this.mongoose)
            console.log("Connected to MongoDB Database");
        return true;
    }
}
export default new MongoConnection();
//# sourceMappingURL=MongoDB.js.map

Seeking insights into the error encountered during setup.

Answer №1

I finally cracked the code.

The problem lied in the usage of async onstart(). The correct syntax should be async onStart().

I was typing a bit too hastily and missed capitalizing the S..

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with implementing setCallBack for updating variant prices in Shopify

I'm currently attempting to update the price of a product when a variant is chosen. I've tried implementing the following code, but haven't been successful in getting it to function properly. The script has been added to the theme.liquid fi ...

Enabling and disabling features in Angular 7 based on a click event

Utilizing Angular 7 along with Typescript 3.1.1 Aim The objective is to implement click events that cannot be triggered again until the previous click event is completed, regardless of the outcome. Illustration <div> <span *ngFor="let a of ...

Path taken to reach the view requested by Node.js server

Snippet of Controller Code: bina: function(req, res) { var request = require('request'); request({ url: 'http://localhost:3000/bina/', method: 'GET', }, function(err, res, body) { ...

What are some ways to verify if the array is absent within a <tr> element in Vue.js?

When my back-end service returns a JSON array with values, everything works fine. But when it doesn't have any values, I encounter an error in my front-end: "[Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined" ...

Combining all code in Electron using Typescript

I am currently working on developing a web application using Electron written in Typescript and I am facing some challenges during the building process. Specifically, I am unsure of how to properly combine the commands tsc (used to convert my .ts file to ...

Error: NgFor can only be used to bind to data structures that are iterable, such as Arrays. JSON arrays are

Encountering ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables like Arrays. *ngFor="let spec of vehicleSpecs" Tried various solutions and searched extensi ...

Incorporate an array into a JSON object using AngularJS

I'm attempting to append a JSON array to a JSON object. Here's my code: $scope.packageElement = { "settings": [ { "showNextPallet": true, "isParcelData": false, "isFreightData": true, " ...

How to select the final td element in every row using JQuery or JavaScript, excluding those with a specific class

I am looking for a solution with my HTML table structure: <table> <tbody> <tr> <td>1</td> <td>2</td> <td class="treegrid-hide-column">3</td> < ...

List output with jQuery AJAX showing object data

Here is my code that utilizes ajax for searching: $("#keyword").keyup(function() { var keyword = $("#keyword").val(); if (keyword.length >= MIN_LENGTH) { $.get( "./lib/data_siswa_ajax.php", { keyword: keyword, sekolah: $("#sekolah").val ...

I am currently working on determining whether a given string is a palindrome or not

I'm currently working on a function that checks whether a given string is a palindrome. So far, my tests are passing except for the following cases: (_eye, almostomla, My age is 0, 0 si ega ym.) This is the function I've implemented: function pa ...

Ways to retrieve information from a $$state object

Everytime I try to access $scope.packgs, it shows as a $$state object instead of the array of objects that I'm expecting. When I console log the response, it displays the correct data. What am I doing wrong? This is my controller: routerApp.controll ...

Can one assign the type of a sibling property to another property within a nested object?

In search of a solution: I am attempting to develop a function, which we'll refer to as test, designed to handle nested objects with dynamic keys on the first level. The goal is for this function to automatically suggest the type of method without req ...

displaying li tag depending on the index value within angularjs

I have an HTML structure similar to the following: <div class="main"> <ul> <li ng-repeat='save in saves'> <h3>{{save.name}}</h3> <div > <ul> ...

Error occurs in ReactJS App when the state is updated in Redux only after dispatching the same action twice

Check out the following code snippet: ChartActions.js import * as types from './ChartTypes.js'; export function chartData(check){ return { type: types.CHART_DATA,check }; } ChartTypes.js export const CHART_DATA = 'CHART_DATA ...

An issue with the image filter function in JavaScript

I am currently working on a simple application that applies image filters to images. Below is the code I have written for this purpose. class ImageUtil { static getCanvas(width, height) { var canvas = document.querySelector("canvas"); canvas.widt ...

Changing the text color and background color of a span element when a ng-click event is triggered

There are two buttons, Today and Tomorrow, each with an ng-click function. By default, the button background color is white and text color is red. When the Today button is clicked, the background color changes to blue and the text color changes to white. ...

Setting a timeout for loading an external JavaScript file that is currently inaccessible

Using JavaScript, I am integrating content from a PHP file on a different server. Unfortunately, this external service can be unreliable at times, causing delays in loading or not loading at all. I am looking for a way in JavaScript to attempt retrieving ...

Adding a total property at the row level in JavaScript

Here is a JavaScript array that I need help with: [{ Year:2000, Jan:1, Feb: }, {Year:2001, Jan:-1, Feb:0.34 }] I want to calculate the total of Jan and Feb for each entry in the existing array and add it as a new property. For example: [{ Year:2000, Ja ...

Tips for getting JavaScript to identify a context_dict object from views.py in Django

Recently, I inherited a Django project from a former colleague and now I need to make some changes to the code in order to add a new line to a Google Viz line chart. As the line chart already exists, my approach is to closely follow the logic used by my p ...

What is the best method for retrieving a local value in Javascript?

Consider a scenario where there exists a variable named animationComplete (which is part of a 3rd-party library) and a function called happenAfterAnimation: An easy solution would involve the following code snippet: while(!animationComplete) { // Do n ...