I'm trying to test solidity code with truffle. As the number values returned from (or sent to) contracts are BigNumber
s I want to require the library. My current test is a one-liner:
let BigNumber = require('bignumber.js');
called hello_test.js.
If I run npm ls -g | grep bignumber
I can see +-- bignumber.js@7.2.1
, so it's installed; but if I try:
truffle.cmd test .\test\hello_test.js
I get
Error: Cannot find module 'bignumber.js'
What's going on?
Truffle version 4.0.6, npm version 5.6.0
This is the way node require works:
require('xx')
will search for
./node_modules/xx.js
./node_modules/xx/index.js
./node_modules/xx/package.json
If it can not find, it will go ahead to search by the environmental variable, NODE_PATH
. If that is not specified, it won't search any global module.
So you can check your NODE_PATH
.