daijinara said over 3 years ago on Deeper Dive into StimulusJS :
better to put this line of code.

import Rails from "@rails/ujs";

Otherwise, Rails.ajax call will be undefined.

Also, adding the intergration with select2 would be better, since it does not fire native events.