Uncaught Reference error: require is not defined [duplicate]

Below code cause this issue

 return iconLists.reduce((list, name) => {
    const pL = list;
    pL[name] = require(`./svg/${name}.svg`)
    return pL 
 }, {})
}

tried different plugins no luck.

vite.config.js

import commonjs from '@rollup/plugin-commonjs'
// import vitePluginRequire from 'vite-plugin-commonjs';
export default defineConfig({
 plugins: [
   react(),
   commonjs(),
 ]
})

Thanks in advance.