0

I am working on a chat app and found the error below:

Module parse failed: Unexpected token (27:14)
You may need an appropriate loader to handle this file type.
|       columnNumber: 17
|     }
>   }), message?.attachments?.length > 0 ? /*#__PURE__*/React.createElement("img", {
|     src: message.attachments[0].file,
|     alt: "message-attachment",

Below is the sample code:

import React from "react";
const TheirMessage = ({lastMessage, message}) => {
    const isFirstMessageByUser = !lastMessage || lastMessage.sender.username != message.sender.username;
    return (
        <div className = "message-row">
            {isFirstMessageByUser && (
                <div 
                    className='message-avatar' 
                    style={{backgroundImage: 'url(${message?.sender?.avatar})'}}
                    />
            )}
            {message?.attachments?.length > 0
                    ? (
                        <img 
                            src={message.attachments[0].file}
                            alt='message-attachment'
                            className="message-image"
                            style={{marginLeft: isFirstMessageByUser ? '4px': '48px'}}
                        />
                    ) : (
                            <div className="message" style={{float: 'left', backgroundColor: '#CABCDC', marginLeft: isFirstMessageByUser ? '4px': '48px'}}>
                             {message.text}
                            </div>
                    )}        
        </div>
    )
}
export default TheirMessage;

I have no clue on how to go about it. Any feedback from you guys is highly appreciated.

Muema
  • 57
  • 1
  • 5
  • This may be a relevant thread to you: https://stackoverflow.com/questions/45848055/image-you-may-need-an-appropriate-loader-to-handle-this-file-type – Wesley LeMahieu Feb 07 '23 at 20:30
  • 1
    I think the issue is over here:- `style={{backgroundImage: 'url(${message?.sender?.avatar})'}}`. It should be backticks ` and not the single quote`'` – Harsh Tuwar Feb 07 '23 at 21:27

0 Answers0