运行npm install run时出错

时间:2020-07-16 21:26:05

标签: node.js

我有一个要运行的github存储库: https://github.com/dappuniversity/price-bot

我做了git clone "above link"npm install多,我得到了以下错误: https://pastebin.com/HRBVAcKF

当我跑步时 `npm run start我遇到了那些错误

> trading-bot@0.3.0 start /home/ether/Desktop/price-bot
> node index.js

Error: Mnemonic invalid or undefined
    at checkBIP39Mnemonic (/home/ether/Desktop/price-bot/node_modules/@truffle/hdwallet-provider/src/index.ts:74:15)
    at new HDWalletProvider (/home/ether/Desktop/price-bot/node_modules/@truffle/hdwallet-provider/src/index.ts:104:23)
    at Object.<anonymous> (/home/ether/Desktop/price-bot/index.js:18:23)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! trading-bot@0.3.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the trading-bot@0.3.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ether/.npm/_logs/2020-07-16T20_51_12_835Z-debug.log

我该如何解决这些错误?

1 个答案:

答案 0 :(得分:1)

该错误有点神秘,因为它起源于一个可能不熟悉的模块。但这就是为什么要获得堆栈跟踪的原因。您只需要逐行查看以查看您的代码中导致错误的那一行。

at checkBIP39Mnemonic (/home/ether/Desktop/price-bot/node_modules/@truffle/hdwallet-provider/src/index.ts:74:15)
at new HDWalletProvider (/home/ether/Desktop/price-bot/node_modules/@truffle/hdwallet-provider/src/index.ts:104:23)
at Object.<anonymous> (/home/ether/Desktop/price-bot/index.js:18:23)

at Object.<anonymous>行指向price-bot/index.js的第18行,这是您要运行的主要代码,并且是您实际控制的代码,与模块不同。因此,转到第18行,您会看到:

// WEB3 CONFIG
const web3 = new Web3(new HDWalletProvider(process.env.PRIVATE_KEY, process.env.RPC_URL) )

基于错误显示“助记符无效或未定义”的事实,我猜测process.env.PRIVATE_KEYprocess.env.RPC_URL均未定义。在进一步检查中,代码使用dotenv,如您在顶部看到的那样:

require('dotenv').config()

..这是负责填写process.env的模块。这些值未定义意味着您可能在项目中缺少正确的.env文件。我可以在存储库中看到.env.example,它显然是项目希望您填写的环境变量的模板:

RPC_URL="https://ropsten.infura.io/v3/YOUR_API_KEY"
PRIVATE_KEY="0x..."
ACCOUNT="0x..."

因此,您需要做的就是将.env.example重命名为.env,然后编辑内容,并使用实际的私钥,api密钥等填充占位符数据。