'Cannot find module when loading non existing assets

I'm trying to load images from a Nuxt component (not a page) like below:

<img
  :src="require(`~/assets/logo/${imageCode}.svg`)"
  @error="$event.target.src = require('~/assets/logo/error.svg')"
/>

But when an image doesn't exist, I'm getting the following error in the browser's console:

Error: Cannot find module './123.svg'

How should I deal with non-existing assets ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source