Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

See error if src is undefined. #1299

Closed
cfdxkk opened this issue Mar 23, 2024 · 3 comments
Closed

See error if src is undefined. #1299

cfdxkk opened this issue Mar 23, 2024 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@cfdxkk
Copy link

cfdxkk commented Mar 23, 2024

Version

dependencies:
  '@nuxt/image':
    specifier: ^1.4.0
    version: 1.4.0
  nuxt:
    specifier: ^3.10.3
    version: 3.10.3(vite@5.1.5)
  vue:
    specifier: ^3.4.19
    version: 3.4.21
  vue-router:
    specifier: ^4.3.0
    version: 4.3.0(vue@3.4.21)
Visual Studio Code: 1.87.2
Vue - Official: v2.0.7

Issue

ERROR: input must be a string (received undefined: undefined)
In my VS Code, It shows that src is optional and can be string or undefined , but if I actually use undefined I get this error.
My TypeScript was broked?

update: const imageUrl = ref<string>(""); also don't work and get error.

image
image

Minimal Reproduction

Source Code: https://github.com/cfdxkk/nuxt-image-undefined-src

app.vue

<template>
	<NuxtImg :src="undefined" />
</template>

or

app.vue

<script setup lang="ts">
	const imageUrl = ref<string>();
	if (false) {
		imageUrl.value = 'foo.jpg'
	}
</script>

<template>
	<NuxtImg :src="imageUrl" />
</template>
@danielroe danielroe added bug Something isn't working good first issue Good for newcomers labels Mar 23, 2024
@cfdxkk
Copy link
Author

cfdxkk commented Mar 23, 2024

update:

Use v-if with :src can temporary fix.

<script setup lang="ts">
	const imageUrl = ref<string>("");
</script>
<template>
	<NuxtImg v-if="imageUrl" :src="imageUrl" />
</template>

@oritwoen
Copy link

I had a similar problem too. Quite by accident, I discovered that adding the parameter: placeholder with the correct url link will display this placeholder image instead of an error if src is empty or has values not defined correctly. It's not a perfect solution but it works.

@danielroe
Copy link
Member

resolved in #1300.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants