【发布时间】:2021-10-28 17:12:57
【问题描述】:
我用npm init vite bar -- --template vue 创建了一个全新的项目。我已经完成了npm install web3,我可以看到我的package-lock.json 包含这个包。我的node_modules 目录还包括web3 模块。
然后我将此行添加到main.js:
import { createApp } from 'vue'
import App from './App.vue'
import Web3 from 'web3' <-- This line
createApp(App).mount('#app')
我不明白这里发生了什么。我对使用npm 还很陌生,所以我不太确定谷歌是什么。错误来自node_modules/web3/lib/index.js、node_modules/web3-core/lib/index.js、node_modules/web3-core-requestmanager/lib/index.js,最后是node_modules/util/util.js。我怀疑它与以下之一有关:
- 我正在使用 Vue 3
- 我正在使用 Vue 3 组合 API
- 我正在使用 Vue 3 Composition API SFC
<script setup>标签(但我在main.js中导入了它,所以我认为不是这个) -
web3js在 Typescript 中,我的 Vue3 项目没有为 Typescript 配置
但由于我对 JavaScript、Vue 和 Web3 还很陌生,所以我不确定如何将我的谷歌搜索重点放在这个错误上。我的背景是 Python、Go、Terraform。基本上是后端的后端。前端 JavaScript 对我来说是新的。
我该如何解决这个问题?
【问题讨论】:
-
然后我得到
Uncaught ReferenceError: global is not defined并出现类似的错误链......