In my package.json
file, I have:
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.0.0",
"chai-bignumber": "^2.0.0",
"decimal.js": "^10.0.0",
"ethereumjs-testrpc-sc": "6.1.2",
"ganache-cli": "6.1.0",
"solidity-coverage": "0.4.14",
"truffle": "4.1.3"
}
I created a NodeJS script file getWeb3Version.js
:
let web3 = require("web3");
console.log(web3.version);
When I run node getWeb3Version.js
before npm install
, I get 1.0.0-beta.30
.
When I run node getWeb3Version.js
after npm install
, I get undefined
.
In order to investigate deeper, I changed console.log(web3.version)
to console.log(web3
), and it appears that the web3
object after npm install
is a very small subset of the web3
object before npm install
.
In order to investigate even deeper, I called npm list --depth=0
from inside and from outside of my project folder (where the package.json
file is located).
When I call npm list --depth=0
from inside of my project folder, I get this:
+-- chai@4.1.2
+-- chai-as-promised@7.1.1
+-- chai-bignumber@2.0.2
+-- decimal.js@10.0.0
+-- ethereumjs-testrpc-sc@6.1.2
+-- ganache-cli@6.1.0
+-- solidity-coverage@0.4.14
`-- truffle@4.1.3
As you can see, web3
is not even there (which is obvious, because I do not import it in my package.json
file).
Nevertheless, require("web3")
seems to work, as mentioned at the beginning of the question.
When I call npm list --depth=0
from outside of my project folder, I get this:
+-- chai@4.1.2
+-- decimal.js@9.0.1
+-- ethereumjs-testrpc-sc@6.0.7
+-- ganache-cli@6.1.0
+-- log4js@2.5.2
+-- pug@2.0.0-rc.4
+-- solc@0.4.19
+-- solidity-coverage@0.4.14
+-- solidity-parser-sc@0.4.4
+-- sprintf-js@1.1.1
+-- testrpc@0.0.1
+-- truffle@4.1.7
`-- web3@1.0.0-beta.30
Followed by a bunch of lines starting with npm ERR! extraneous:
.
What exactly is going on here?
Is it possible that one of the packages imported in my package.json
file exports the subset of the web3
object that I see when I do console.log(web3)
?