In order to publish a SharePoint hosted app to a site collection the site must be based on the developer site template or have the “Developer” Feature enabled on it. The “Developer” Feature is marked as hidden in its definition so you must use PowerShell to enable the Feature. This error is caused when you try to deploy in a non-developer template site collection.
To avoid this error, either for SharePoint online or On-premise development, try first to create a site collection based on the Developer template and deploy your SharePoint-hosted app to this site collection. If you are deploying to a non-developer template site collection, which is something you shouldn’t be doing then here are the live links to download the SharePoint Online Management Shell i.e. for SharePoint online scenario and associated PowerShell scripts as described in the screenshot below: