dfinity / agent-js

A collection of libraries and tools for building software around the Internet Computer, in JavaScript.
https://agent-js.icp.xyz
Apache License 2.0
151 stars 94 forks source link

[vite]: Rollup failed to resolve import "vite-plugin-node-polyfills/shims/global" #901

Closed baolongt closed 1 month ago

baolongt commented 1 month ago

My project using vite for bundle and when I run tsc -b && vite build

it return this error

error during build:
[vite]: Rollup failed to resolve import "vite-plugin-node-polyfills/shims/global" from "<project path>/node_modules/@dfinity/agent/lib/esm/agent/index.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to

My vite.config.ts file

import path from "path"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
import { nodePolyfills } from 'vite-plugin-node-polyfills'
export default defineConfig({
  plugins: [react(), nodePolyfills({
    globals: {
    },
  }),],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
})
baolongt commented 1 month ago

This because my local dependencies does not install vite-plugin-node-polyfills you should install it