creator 3.3 引入web3js,报错,

使用 import Web3 from "./web3/web3.min.js" 导入
start () {
        let web3 = null;
       //初始化过程
       if (typeof web3 !== 'undefined') {
          web3 = new Web3(web3.currentProvider);
        } else {
        // set the provider you want from Web3.providers
           web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7456"));
        }
        let from = web3.eth.accounts[0];
        console.log('from====' +  from);
      
    }
报错
Uncaught Error: Unable to resolve bare specifier '__unresolved_0' from http://localhost:7456/scripting/x/mods/fs/0/node_modules/web3/lib/index.js (SystemJS Error#8 https://git.io/JvFET#8)

NewProject_4.zip (41.8 KB)
记得先在工程目录执行下:npm install --save web3
具体可参考:React App

谢谢您我试试 :grinning: :grinning:

一起学习呀:grinning: 才入坑 资料少得一批

我按照 React App依然报错啊

12

vscode 控制台输入 npm install --save web3 回车 然后 图片里面就可以跑

谢谢,我的问题已经解决了,我用require报错,import Web3 from “web3/dist/web3.min.js”;这样可以,而且不用设置tsconfig就可以用了

学习了,之前2.x用的是 min.js作为插件的方式实现的, 目前还未解决api代码提示的问题,每次都得自己去找api,楼主解决api提示了吗

还是没有提示

看下 Can I use … npm module… (cocos-creator.github.io)

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。