Add error or success messages with javascript
define(
[
'jquery',
'Magento_Customer/js/customer-data',
'mage/translate'
],
function($,$customerData){
var showMessage = function(){
var nameProduct = 'this is the message';
var messageError = $.mage.__('%s has already started.').replace('%s', nameProduct);
customerData.set('messages', {
messages: [{
type: 'error',
text: messageError
}]
});
}
}
);