通过导入访问时使用变量挂起构建过程

问题描述

我正在构建一个全栈应用程序,并且正在使用prisma和Web3。作为prisma构建过程的一部分,我使用@H_502_1@yarn generate来编译架构。我遇到了一个奇怪的问题,我的程序挂在return语句上。

@H_502_1@// ./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
}
@H_502_1@// ./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 (将#修改为@)