当前位置:网站首页>Vite+web3: referenceerror: process is not defined

Vite+web3: referenceerror: process is not defined

2022-06-24 18:38:00 Ren Lei ABC

The recent use vite Scaffolding a blockchain project , need web3 This dependency Library , But introduce... Into the project web3 after , There is an error :

  The solution is vite The configuration file vite.config.js It's equipped with :

// vite.config.js
import { defineConfig } from 'vite'

export default defineConfig({
  ⋮
  resolve: {
    alias: {
      web3: 'web3/dist/web3.min.js',
    },

    // or
    alias: [
      {
        find: 'web3',
        replacement: 'web3/dist/web3.min.js',
      },
    ],
  },
})

Then it can be introduced normally :

import web3 from 'web3';
console.log(web3);

原网站

版权声明
本文为[Ren Lei ABC]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241323299916.html