Creating ajax modal from event
How can I create a modal popup from a CartEvents::CART_ENTITY_ADD
  event subscriber? Am I missing something to do with the libraries or
  something wrong with my php?


You can't return a response from any event, this is only possible from specific kernel events by setting the response in the event. But the example you have linked should work in your case. It splits the task into two event subscribers:

  public static function getSubscribedEvents() {
    return [
      CartEvents::CART_ENTITY_ADD =&gt; 'onAddToCart',
      KernelEvents::RESPONSE =&gt; 'onResponse',
    ];
  }


which are in the same service class, so the second event can use the variable the first one has set:

  public function onAddToCart(CartEntityAddEvent $event) {
    $this-&gt;purchasedEntity = $event-&gt;getEntity();
  }

  public function onResponse(FilterResponseEvent $event) {
    $response = $event-&gt;getResponse();

    // We only care if this happened after an entity was added to the cart.
    if (!$this-&gt;purchasedEntity) {
      return;

    ...

    $event-&gt;setResponse($response);
  }