简体   繁体   中英

Node can't find Web3 js

I'm kind of new to Node. So, I installed Web3 like this:

npm install -g web3

Success. Then I run node and try to require web3. It doesn't work:

Welcome to Node.js v12.11.0.
Type ".help" for more information.
> Web3 = require('web3')
Thrown:
Error: Cannot find module 'web3'
Require stack:
- <repl>
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:780:15)
    at Function.Module._load (internal/modules/cjs/loader.js:685:27)
    at Module.require (internal/modules/cjs/loader.js:838:19)
    at require (internal/modules/cjs/helpers.js:74:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}

Any ideas, I'm probably missing something obvious.

It looks like the web3 has problems when you globally install it using -g .

I suggest you give npm init to your project if you have not already given it and install it only for your project running:

npm install web3

inside of your project folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM