Trying to automatically add a product in Commerce
I tried this myself and it threw an error when there was no cart attached to the session.

I then found these two lines of code in the Craft Commerce CartController.php:

        // Get the cart from the current users session, or return a new cart attached to the session
        $cart = Plugin::getInstance()-&gt;getCarts()-&gt;getCart(true);


getCart() can be found in the Carts Service

Which lead me to try:

{% set cart = craft.commerce.carts.cart(true) %}


So if you pass in true, you force it to save the cart and thus you seem to be able to create a new (empty) cart.