DEV Community

Adrien Poly
Adrien Poly

Posted on

StimulusJS 2.0 silencing depreciation message

Stimulus 2.0

🚀 The long expected Stimulus 2.0 is Out. The upgrade from 1.1.1 to 2.0 should be very smooth as they are very minimal breaking changes.

Mute the data-target depreciation message in production

The data-target API has changed. While the 1.1 version is still supported. There is a warning message in the console every time an old syntax is seen for the first time.

The best way to fix this of course is to update all data targets but in a large code base this can take some time.

Another solution to gradually update your code is to silence the warning in production.

Here is a snippet to help

import { Application } from 'stimulus'
import { definitionsFromContext } from 'stimulus/webpack-helpers'

const application = Application.start()

// remove Stimulus depreciation warnings in production
if (process.env.NODE_ENV === 'production') {
  application.logger = { ...application.logger, warn: () => {} }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)