反应错误:未定义web3'no-undef

时间:2019-03-01 16:01:37

标签: reactjs web3 web3js

我将web3安装在react-app的文件夹中:

  

npm install-保存ethereum / web3.js

但是我收到反应错误:未定义web3'no-undef

body {
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: 100vh; /* ADDED */
  grid-template-areas: "sb mn";
  grid-column-gap: 10px;
}

.grid>* {
  margin: 0;
  padding: 0;
}

.sidebar {
  grid-area: sb;
  border: 1px solid green;
  /*padding: 0 5px;*/
  background-color: red;
  overflow: hidden; /* ADDED */
}

aside div {
  /* width: 200px; */
  margin: 0;
  padding: 0 5px; /* CHANGED */
  border: 1px solid blue;
  /* padding: 0 15px 0 5px; */
  /* position: fixed; */
}

.main {
  grid-area: mn;
  overflow-y: auto; /* ADDED */
}

2 个答案:

答案 0 :(得分:0)

您应该按照Documentation

所述的方式导入软件包

Named Export而不是Default export

import {Web3} from 'web3';

答案 1 :(得分:0)

如果您以这种方式安装了web3:

npm install --save ethereum/web3.js

请检查您的package.json文件以查看该库的显示方式,可能是ethereum/web3。因此,您的导入应看起来像这样:

import Web3 from 'ethereum/web3'

如果您想从npm安装web3软件包,只需执行以下操作:

npm install --save web3

,然后像导入一样导入。根据{{​​3}}

相关问题