Google Search has not been subject to competitive evolutionary pressures for many years now (because the initial performance of their Page Rank technology was superior to existing engines), so they apparently do pretty much whatever flips their bibby at a given moment (take a look at marsupials or Microsoft Windows for other examples of the result of a lack of competition).
Why do I make this criticism? I have two websites which have been up and well-known for over ten years. They both appeared at top of SERP in any search engine prior to my remimplementation in March at a new host. GSC (Google Search Console) complained about wanting canonical url or the like (claiming duplicate content, blah blah blah), so I settled on using the naked domain, i.e., without the so-called "machine designation" (www). My local .htaccess files at both sites happily redirect any incoming
https://www.target.com etc. into the index.html page (secure connection https though there is no eCommerce or login involved, just forced into SSL by another Google demand basically). I added
<link rel="canonical" ... in the
<head> at both sites, as well as an
xml sitemap defining my preferred location URL for each page of the site.
DuckDuckGo and Bing (I hate to recommend Bing, their idiot child "AI" frantically trying to anticipate my thoughts and making typing in my query clumsy, as admittedly Google does as well) both maintain the top SERP position on my name form, as they should, I being the author who chose the resource identifier that best fits the nature of the concept being defined in mapping the location of my site with its semantics (see Roy Fielding's 2000 PhD dissertation. That concept is simply me, i.e., my name at one and the other my business (IT support, retire now) name known for twenty years.
Google, however, accepts one of my site URLs without www prefix (though perversely displaying sites that refer to my content prior to my canonical site) but demands that I change the other URL to use the www prefix, i.e.,tells me in GSC that they prefer to display that (to which I ask, then why don't you just display www then? my redirect gets you to the site one way or the other).
In apparent fit of pique, Google search now refuses to display the second site at all in SERP on the terms that previously showed top of page (though as I say, those terms still locate me top of SERP in other search engines as before), and as an additional finger in my eye, instead they display sites that link to my site instead.
Yeah, I know, if this was a matter of business (money) I would just cave in to Google's demand for www on the second site, but I have always resented the arbitrary exercise of authority and refuse to do it (instead just providing links to my site wherever I am active online, and recommending people use another search engine if they prefer to search for me instead).
So my answer then is that you may have to use www prefix if you want to satisfy Google (though this is apparently not a consistent demand there).