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:
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
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:
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
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)
?