小编Tha*_*arg的帖子

ReferenceError:全局未使用 web3 定义

一段时间以来,我一直在尝试将 Web3 安装到我的 Ionic v4 项目中。当我为项目提供服务时,它不断抛出错误。我收到一条错误,指出引用错误:全局未定义。

  1. 启动一个新的 Ionic 项目
  2. 安装 web3 : npm install --save web3
  3. 安装节点类型: npm install --save-dev @types/node
  4. 编辑一些代码来访问 web3 :
import { Component } from '@angular/core';
import { Web3 } from 'web3'; 

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/v3/apikey...'));

  constructor() {}

  test(){
    console.log(this.web3);
  }
}
Run Code Online (Sandbox Code Playgroud)
  1. 运行离子服务
  2. 编译成功,但我在谷歌浏览器的控制台中收到这样的错误
core.js:9110 ERROR Error: Uncaught (in promise): ReferenceError: global is not defined
ReferenceError: global is not defined
    at Object../node_modules/stream-http/lib/capability.js (capability.js:1) …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript ionic-framework angular

5
推荐指数
1
解决办法
5713
查看次数