为什么我会在 JSX - x Expression expected 中收到此错误消息?

Why am I getting this error message in JSX - x Expression expected?

我收到错误说明 - x Expression expected 和 Unterminated regexp literal...1

我遇到问题的代码如下:

import Link from 'next/link';
import React from 'react';
import {useContext} from "react";
import {UserContext} from "../lib/context";

// Top Navbar
export default function Navbar() {
    const { user, username } = useContext(UserContext)

    return (
        <nav className='navbar'>
            <ul>
                <li>
                    <Link href="/">
                        <button>FEED</button>
                    </Link>
                </li>

                {/* user is signed in and has username */}
                {username && (
                    <div>
                        <li className='push-left'>
                            <Link href="/admin">
                                <button className="btn-blue">Write Posts</button>
                            </Link>
                        </li>
                        <li>
                            <Link href={`/${username}`}>
                                <img src={user?.photoURL} alt=/>
                            </Link>
                        </li>
                    </div>
                )}


                {/* user is not signed in OR has not created username */}
                {!username && (
                    <li>
                        <Link href="/enter">
                            <button className="btn-blue">Log in</button>
                        </Link>
                    </li>
                )}
            </ul>
        </nav>
    )
}

有人知道为什么会发生这种情况吗?

检查第 29 行。<img src={user?.photoURL} alt=/>

alt 标签应至少包含一个空字符串:

<img src={user?.photoURL} alt=""/>

希望对您有所帮助:)

谢谢,我通过在 HTML/CSS.

中切换到双引号而不是单引号解决了这个问题