Node.js 运行npm安装运行时出错
我有一个要运行的github回购: 我在链接上方做了git克隆 比npm安装,我得到了这些错误: 当我跑的时候 `npm运行开始我收到了这些错误Node.js 运行npm安装运行时出错,node.js,Node.js,我有一个要运行的github回购: 我在链接上方做了git克隆 比npm安装,我得到了这些错误: 当我跑的时候 `npm运行开始我收到了这些错误 > 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/no
> 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
>交易-bot@0.3.0启动/家庭/以太/桌面/价格机器人
>node index.js
错误:助记符无效或未定义
在checkBIP39Mnemonic(/home/ether/Desktop/price bot/node_modules/@truffle/hdwallet provider/src/index.ts:74:15)
新的hdwallet提供商(/home/ether/Desktop/price bot/node_modules/@truffle/hdwallet provider/src/index.ts:104:23)
反对。(/home/ether/Desktop/price-bot/index.js:18:23)
at模块编译(内部/modules/cjs/loader.js:1151:30)
at Object.Module._extensions..js(internal/modules/cjs/loader.js:1171:10)
在Module.load(内部/modules/cjs/loader.js:1000:32)
at Function.Module._load(内部/modules/cjs/loader.js:899:14)
在Function.executeUserEntryPoint[作为runMain](internal/modules/run_main.js:71:12)
在internal/main/run_main_module.js:17:47
npm错误!代码失效循环
npm错误!错误1
npm错误!交易-bot@0.3.0start:`node index.js`
npm错误!退出状态1
npm错误!
npm错误!交易失败-bot@0.3.0开始脚本。
npm错误!这可能不是npm的问题。上面可能还有其他日志输出。
npm错误!此运行的完整日志可在以下位置找到:
npm错误/home/ether/.npm/_logs/2020-07-16T20_51_12_835Z-debug.log
如何修复这些错误?该错误有点神秘,因为它源自可能不熟悉的模块。但这就是为什么会有堆栈跟踪。您只需逐行查看代码中引起错误的那一行
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)
根据错误是“助记符无效或未定义”的事实,我猜测process.env.PRIVATE\u KEY
或process.env.RPC\u 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密钥等填充占位符数据,但它说在atom中,这个文件已经created@bestethereumsites配置文件浏览器以显示隐藏的文件。当我从gitignore中删除条目时:env文件在gitignore中忽略显示的文件,并用api密钥等替换所有内容;但我在运行npm start时仍然会遇到相同的错误run@bestethereumsites首先执行一些基本的调试步骤,例如使用console.log
检查process.env.PRIVATE\u KEY
和process.env.RPC\u URL
的值。如果未设置它们的值,则您的.env
文件仍未正确设置。如果设置了它们的值,并且您收到了相同的错误,那么其中一个肯定是无效的——比如格式错误或者复制了错误的内容。
RPC_URL="https://ropsten.infura.io/v3/YOUR_API_KEY"
PRIVATE_KEY="0x..."
ACCOUNT="0x..."