mobiman
mobiman

Reputation: 639

Node: How Can I Import Web3 To Node.js?

I'm trying to import the web3 library in Node.js so that I can handle Ethereum smart contract events, however I can't get the import to work.

I'm running Babel on each file to convert to es5, and the import in Node's index.js file looks like this:

import Web3 from 'web3'; 

When I add that "import Web3 from 'web3'" statement I get this error:

webpack:///./node_modules/scrypt/index.js?:3
var scryptNative = __webpack_require__(!(function 
webpackMissingModule() { var e = new Error("Cannot find module 
'./build/Release/scrypt'"); e.code = 'MODULE_NOT_FOUND'; throw e; } . 
()))

^

Error: Cannot find module './build/Release/scrypt'
at webpackMissingModule 
(webpack:///./node_modules/scrypt/index.js?:3:84)
at eval (webpack:///./node_modules/scrypt/index.js?:3:181)
at Object../node_modules/scrypt/index.js 

This is my version of web3: (However, I have tried other versions which also don't work)

"web3": "^1.0.0-beta.26"

Does anyone know how I can import the web3 library to Node? Any help is greatly appreciated.

Upvotes: 1

Views: 3270

Answers (3)

Nikhil Singh
Nikhil Singh

Reputation: 21

After install web3 using npm install web3, you can import the web3 module using the following line inside your .js file

var web3 = require('web3');

Upvotes: 0

leonprou
leonprou

Reputation: 4878

Name of the module should be quoted

import Web3 from 'web3';

Upvotes: 1

sgeorgiou
sgeorgiou

Reputation: 89

Try using the require for this module:

const web3 = require('web3');

Upvotes: 0

Related Questions