如何解决通过导入访问时使用变量挂起构建过程
我正在构建一个全栈应用程序,并且正在使用prisma和Web3。作为prisma构建过程的一部分,我使用yarn generate
来编译架构。我遇到了一个奇怪的问题,我的程序挂在return语句上。
// ./modules/Wallet.ts
import Web3 from 'web3'
// create a Web3 connection
export const web3 = new Web3(
process.env.NODE_ENV === 'production'
? 'wss://mainnet.infura.io/ws/v3/redacted'
: 'wss://ropsten.infura.io/ws/v3/redacted'
)
// load an Ethereum wallet from a private key (env var)
const envWallet = () => {
if (!process.env.ETH_PRIVATE_KEY) {
require('dotenv').config()
}
const _wallet = web3.eth.accounts.wallet.add(process.env.ETH_PRIVATE_KEY!)
// successfully logs the loaded wallet on `yarn generate`
console.log(_wallet)
// Issue: `yarn generate` hangs on this line
return _wallet
}
// initialize the wallet
const wallet = envWallet()
// get the address of the wallet
export const getAddress = () => {
return wallet.address
}
// ./types/Query.ts
// If I omit this file from the schema,it will compile successfully
import { queryType } from '@nexus/schema'
import { getAddress } from '../modules/Wallet'
console.log('Test 1') // logged after the console.log(_wallet)
const Query = queryType({
deFinition(t) {
// simply a GraphQL query that returns the address of the loaded wallet
t.string('getAddress',{
nullable: true,resolve: (root,args,ctx) => {
console.log('Test 2') // never hits
const address = getAddress()
console.log('Test 3') // never hits
return address
},})
},})
export default Query
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。