Questions tagged [require]

In programming languages such as Lua, PHP, and Ruby, the "require" statement instructs the interpreter to incorporate a specific source file at the location where the "require" statement is written.

I'm encountering a strange issue where Node JS is mistakenly claiming that the method doesn't exist, even though

Ah, it seems I've encountered an error in my test project. The issue lies with Node JS not being able to locate the getStr function within the Another object. Allow me to share the code with you: test.js var Another = require('./another.js'); var Other ...

Switching the Require statement to an Import statement led to an error popping up

Currently, I am exploring the use of Ajv with typescript. import { Ajv } from "ajv"; let ajv = new Ajv({allErrors: true}); I have encountered an error and I'm unsure why it is occurring: [ts] 'Ajv' only refers to a type, but is being used as a value ...

Tips for creating a Node.js file that is accessible through the command line and can also be imported using the 'require()' function in other files

I am looking to create a Node.js source file called myCode.js that contains a function named foo(arg1, arg2,..). I want to be able to execute this function from the command line using: $ node ./myCode.js arg1 arg2 And also be able to use it in another fi ...

Can one bring in a JavaScript function using webpack?

I have a unique JS library called: say-my-greeting.js function SayMyGreeting (greeting) { alert(greeting); } Now I want to incorporate this function in another (.ts) file; special-class.ts import SayMyGreeting from './say-my-greeting.js' ex ...

What steps are involved in bundling a Node project into a single file?

Recently, I've been using npm to create projects. When it comes to AMD, I find the native node require to be very convenient and effective for my needs. Currently, I rely on grunt-watchify to run my projects by specifying an entry file and an output file. ...

Need to import Vue component TWICE

My question is simple: why do I need to import the components twice in the code below for it to function properly? In my current restricted environment, I am unable to utilize Webpack, .vue Single File Components, or npm. Despite these limitations, I mana ...

Webpack dynamically imports files from a folder

In order to streamline my development process, I have a specific structure for organizing React components. Each main component has its own components folder right alongside it. Currently, I find myself manually importing each component from the components ...

Using Internet Explorer with Vuejs may require adding a polyfill for Promise support

Having no prior experience with Vuejs, I found myself in a situation where I needed to debug code for Internet Explorer. The first problem was fixing all arrow Functions, which wasn't too difficult to handle. The second issue is that I am not able to ...

Create a fresh instance of an object in node.js by utilizing the require/new method

I am encountering a beginner problem with node.js where I cannot seem to create objects using the 'new' operator in the index.js file. My goal is to define a simple Person object within a Person.js file, located in the same directory as my index ...

Widget function discrepancy

Here is the code for registering a widget in the sidebar: // Sidebar Register add_action('widgets_init', 'comet_sidebar'); function comet_sidebar() { register_sidebar(array( 'name' => __('Right ...

What is preventing me from utilizing require in vue-router's routes.js file?

Vue-router typically requires the standard setup as outlined below: In main.js, the routes.js file is required and it usually contains code similar to this: //routes.js import Register from './components/Register' import Login from './comp ...

When attempting to deploy my application on Heroku, I encountered the error message "ReferenceError: require

My NodeJS project works fine locally but encounters issues when deployed on Heroku. Upon running "heroku logs --tail" for error checking, the following message is displayed: 2020-08-18T10:39:44.396002+00:00 app[web.1]: const express = require('expres ...

React - Dynamically import file path for PDF document

Initially, the page will send an http request to an API The API will then respond with an object containing a path: ./assets/sample.pdf I am trying to extract the urlPdf from import urlPdf from response.path Any suggestions on how I can achieve this? ...

Struggling to troubleshoot node.js "Unable to locate module xyz/abcd"

I'm encountering the error message Error: Cannot find module xyz/abcd. Yes, I have confirmed that the required module is indeed installed. Based on the information provided in the pseudo-code of module.require, it should be functioning correctly. I ...

Improve your code quality with TypeScript's type checking capabilities

I am currently utilizing TypeScript version 1.4.1 and I have a need to import an external module (specifically "chai") while ensuring type checking compatibility. Yet, I seem to be facing a naming conflict issue with the following code snippet: /// <r ...

Experiencing difficulties when attempting to send an SMS to a phone number through MessageBird

When attempting to send a test SMS, I encountered an error in the first line of code stating that require(...) is not a function. Here is the code snippet: const messagebird = require('messagebird')('<YOUR_ACCESS_KEY'); var messageO ...

Error: 'require' function is not recognized in the latest JavaScript file

I am interested in using anime.js. To install this library, I need to follow these steps: $ npm install animejs --save const anime = require('animejs'); The code should be written in a js file named "anime.js" Here is the code for "anime.js": ...

Implementing Singletons in Node.js

While examining some code, I came across the following snippet: var Log = require('log'); // This creates a singleton instance module.exports = new Log('info'); Initially, my reaction was doubting that it could be considered a single ...

Encountered an uncaughtException in Node.js and mongoDB: User model cannot be overwritten once compiled

Currently, I am utilizing this import statement const User = require("./Usermodel")' However, I would like to modify it to const User = require("./UserModel") Despite my efforts to align the spelling of the import with my other import ...

Development of a node app along with several node modules happening simultaneously, utilizing npm-link for seamless integration

I've been immersed in building a node.js app while simultaneously working on the necessary modules. The challenge I'm facing involves dealing with peerDependencies and finding the optimal setup for my development environment. Here's what I have set up so ...

The call signatures for `node-fetch -- typeof import("[...]/node-fetch/index")'` are not properly defined

Originated from this source: https://github.com/node-fetch/node-fetch#json ... my personal code: const fetch = require('node-fetch'); async function doFetch() { const response = await fetch('https://api.github.com/users/github'); ...