Difficulty encountered when using `require('bignumber.js')` in Truffle test, despite successful installation as shown by `npm ls -g` (Windows)

While exploring solidity code testing with truffle, I encountered the need to work with BigNumber values returned from or sent to contracts and decided to include the appropriate library. My current test consists of just one line:

let BigNumber = require('bignumber.js');

This test file is named hello_test.js.

When running the command npm ls -g | grep bignumber, it confirms that

+-- <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="385a515f564d555a5d4a16524b780f">[email protected]</a>
is installed. However, when trying to execute:

truffle.cmd test .\test\hello_test.js

An error occurs:

Error: Cannot find module 'bignumber.js'

I am puzzled by this issue. Any insights?

Running Truffle version 4.0.6 and npm version 5.6.0

Answer №1

Here is a breakdown of how node require functions: require('xx') will look for

./node_modules/xx.js
./node_modules/xx/index.js
./node_modules/xx/package.json

If it cannot locate the file, it will then search using the environmental variable, NODE_PATH. If NODE_PATH is not specified, it will not search in any global modules.

Make sure to verify your NODE_PATH.

Answer №2

For some reason, the solution was to locally install the bignumber.js package:

C:\project\> npm install bignumber.js
+ <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81e3e8e6eff4ece3e4f3afebf2c1b6afb3afb0">[email protected]</a>
added 1 package and moved 1 package in 4.222s

C:\project\> truffle.cmd test .\test\hello_test.js

  0 passing (2 ms)

Following this installation, the bignumber.js package can now be found in both npm ls -g and npm ls (when executed from the project's root directory).

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

Before displaying the rows stored in the controller, ng-repeat initially displays one row

I am experiencing an issue with my back end service sending data to a $scope variable. I am using this variable to populate rows in a table with ng-repeat. Upon loading the page, initially one row is visible on the browser but then disappears once the loa ...

Is there a need to manually install npm packages yourself?

Currently, I am delving into the world of protractor and following a tutorial on Github. After successfully downloading protractor and proceeding with webdriver-manager update I encountered a failure which includes errors such as: downloading http://se ...

What is the typical approach for handling dependencies when deploying in a production environment using NPM?

Currently, our frontend project utilizes webpack and npm for dependency management. When configuring Jenkins for automating the deployment process to both the 'test' and 'production' environments, we follow these steps: rm -rf node_m ...

Determining the JavaScript event source within a function's scope: A guide

Query Can we determine the origin of a function being triggered by either a user event or an async event, without having access to the original event parameter? Situation I am faced with the challenge of identifying the event source within a nested funct ...

What is the reason for X being set to the maximum length during every iteration?

As I work on generating a two-dimensional array of objects, each object has its own X and Y coordinates. The instantiation process seems to be correct as confirmed by console logging and the position in the array aligning with the values. However, upon lo ...

What could be the reason for the Mootools Multibox images displaying scrollbars when initially viewed?

We have implemented the Mootools Multibox plugin to showcase our images. Upon the initial viewing in Chrome and Safari, we noticed that the images are zoomed in and display with scrollbars. However, upon refreshing the page, the images render correctly wi ...

Developing an array-based multiple choice quiz

Being a complete novice, I am currently immersed in designing a multiple-choice quiz using arrays. The questions all follow a similar template: "Which word in the following has a similar meaning to '_________'." To implement this, I have created ...

Utilizing user input to execute an API request

I am working with a form that allows the user to input a city name. I want to use an API call to retrieve weather data for that specific city and display it in the console. Unfortunately, I'm encountering an error where the variable containing the in ...

How can I integrate custom PHP pages into Odoo Community 12?

I am looking for a way to integrate my custom PHP webpages with the login page of Odoo Community that is already set up and functioning on my server. I want specific users to be redirected to my custom pages after logging in. Any suggestions on how to ac ...

Having trouble getting the Sass module to install on gulp.js with node.js

Every time I try to run npm install gulp-sass --save-dev, I encounter the same error: gyp ERR! build error gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1 gyp ERR! stack at ...

Attempting to execute JavaScript within HTML files that have been incorporated using Angular

My website has a menu designed in HTML, and instead of manually adding it to each page (which would make updating changes tedious), I am using Angular to include it dynamically (<div ng-include="menu.html"></div>). I've got some JavaScrip ...

Unpredictable order of replies retrieved using $http.get

I am struggling to create a function that sends multiple requests to the server based on the number of Ids in the idArray. The issue I am encountering is that the data being pushed into the dataArray does not align with the corresponding Ids of the idArr ...

vue v-if="canEdit" @click.prevent

I have a Vue component called 'test' with specific template and methods. The goal is to make the div clickable only if helper.isEditable is true, otherwise it should be notClickable or touchable. However, I can only retrieve the value of helper. ...

Is it necessary to delete the node_modules folder before running NPM install for it to work properly?

I have encountered an issue with my Visual Studio Team Services build definition that includes a first step of "npm install". This definition is set up to deploy to an Azure web app. Even though NPM installation completes without any errors, when accessin ...

Trouble viewing images on Vercel deployment, yet they display correctly on localhost

Having deployed my Node application on Vercel at node-demo-ashen.vercel.app, I am facing an issue where the images are not loading on Vercel as expected. Strangely, they load perfectly fine on localhost:3000. Despite multiple configurations made to the ver ...

Vue.js event handlers

I am in the process of creating a basic app that will include a few listeners. However, I am struggling to determine the best approach for organizing the logic behind it. Here is an example of the HTML: <div id="playerProgressBar"> <div id=" ...

Tips for incorporating inline styling into the body element

Can someone help me with adding inline style to the body element using jQuery? I want to set the background color to white (#FFFFFF). Your assistance would be highly appreciated. Thank you! ...

Using lazy loading and $ocLazyLoad for improved performance

Recently, I stumbled upon the $ocLazyLoad third-party Angular module that allows for the lazy loading of JavaScript files. This concept has me a bit perplexed. Can you explain the difference between lazy loading and caching, and why one would choose to l ...

Leveraging require in AWS lambda operations

As part of my exploration into AWS Lambda functions, I've been trying to determine if the require statement can be used within them. This would allow me to incorporate other non-lambda functions into my code. Although zipping the node modules folder i ...

I'm absolutely obsessed with it: Error - unable to switch to an abstract state

Hey there! Currently, I'm working on an app using the IONIC Framework and running into some issues with user validation errors. Below, you'll find a snippet of the logic I've implemented: app.js: angular.module('skulApp', [' ...