vite 使用 iconv-lite

vite使用iconv-lite会报错

chunk-TJNH2AAH.js?v=16c54780:24 Module "buffer" has been externalized for browser compatibility. Cannot access "buffer.Buffer" in client code.
chunk-P7CRJOKS.js?v=16c54780:903 Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
    at node_modules/.pnpm/[email protected]/node_modules/safer-buffer/safer.js (iconv-lite.js?v=dcaf0aee:33:37)

安装 vite-plugin-node-polyfills
配置 vite.config.js

import { nodePolyfills } from 'vite-plugin-node-polyfills';

export default {
  plugins: [ nodePolyfills()],
};

你可能感兴趣的:(javascript,前端)