In one of the projects that I’m working on, I recently encountered a conflict between Underscore library used within WordPress and the Lodash library used with the Theme I was working on.
I knew from the console errors that the conflict arises because both use _. syntax. I knew that I must use _.noConflict() but I didn’t know where to.
One of my fellow developers came up with the following solution to solve the issue.
wp_enqueue_script( 'et-onboarding', $BUNDLE_URI, $BUNDLE_DEPS, (string) $cache_buster, true );
wp_add_inline_script( 'et-onboarding', '_.noConflict(); _.noConflict();', 'after' );
wp_localize_script( 'et-onboarding', 'et_onboarding_data', self::get_onboarding_helpers() );
I’m fortunate to be part of a team of brilliant folks.