简体   繁体   English

Node:如何将 Web3 导入 Node.js?

[英]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.我正在尝试在 Node.js 中导入 web3 库,以便我可以处理以太坊智能合约事件,但是我无法导入工作。

I'm running Babel on each file to convert to es5, and the import in Node's index.js file looks like this:我在每个文件上运行 Babel 以转换为 es5,Node 的 index.js 文件中的导入如下所示:

import Web3 from 'web3'; 

When I add that "import Web3 from 'web3'" statement I get this error:当我添加“从‘web3’导入 Web3”语句时,出现此错误:

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 版本:(但是,我尝试过其他版本也不起作用)

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

Does anyone know how I can import the web3 library to Node?有谁知道如何将 web3 库导入 Node? Any help is greatly appreciated.任何帮助是极大的赞赏。

Name of the module should be quoted应该引用模块的名称

import Web3 from 'web3';

Try using the require for this module:尝试使用此模块的要求:

const web3 = require('web3');

After install web3 using npm install web3, you can import the web3 module using the following line inside your.js file使用 npm install web3 安装 web3 后,您可以在 .js 文件中使用以下行导入 web3 模块

var web3 = require('web3');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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