reactjssvgvitecommonjs

TypeError: Cannot convert object to primitive value when trying to use template literal in require(`${some_var_string}`)


Try to use lib "react-inlinesvg" in Vite. i have such code:

<SVG src={require(`../../../assets/icons/icon/logo_${themeProp}_full.svg`)} />;

and in result i have:

react-inlinesvg.js?v=ee63b9bd:1002 Uncaught (in promise) TypeError: Cannot convert object to primitive value
    at RegExp.exec (<anonymous>)
    at react-inlinesvg.js?v=ee63b9bd:1002:62
    at react-inlinesvg.js?v=ee63b9bd:1083:7
    at commitHookEffectListMount (chunk-MCEUSTYS.js?v=05c8fdba:16902:34)
    at commitPassiveMountOnFiber (chunk-MCEUSTYS.js?v=05c8fdba:18150:19)
    at commitPassiveMountEffects_complete (chunk-MCEUSTYS.js?v=05c8fdba:18123:17)
    at commitPassiveMountEffects_begin (chunk-MCEUSTYS.js?v=05c8fdba:18113:15)
    at commitPassiveMountEffects (chunk-MCEUSTYS.js?v=05c8fdba:18103:11)
    at flushPassiveEffectsImpl (chunk-MCEUSTYS.js?v=05c8fdba:19484:11)
    at flushPassiveEffects (chunk-MCEUSTYS.js?v=05c8fdba:19441:22)

i add common js plugins in Vite config but it doesn't change anything


Solution

  • I use plugin for vite vite-require and everything works well.