Maybe it's too late with the answer, but I found a solution. I had the same problem myself. It seems that the code is identical, but small details can lead to an error
lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: CollectionViewLayout().createCompositionaLayout())
collectionView.frame = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height)
collectionView.register(PreviewCardPersonCollectionViewCell.self, forCellWithReuseIdentifier: "PreviewCardPersonCollectionViewCell")
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.dataSource = self
collectionView.delegate = self
collectionView.backgroundColor = .red
return collectionView
}()
self.addSubview(collectionView)
collectionView(equalTo: self.leadingAnchor, constant: 20).isActive = true
collectionView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20).isActive = true
collectionView.topAnchor.constraint(equalTo: self.topAnchor, constant: 20).isActive = true
collectionView.heightAnchor.constraint(equalToConstant: 100).isActive = true