Skip to main content

DDEV downgrade npm for Sulu CMS

· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

Adding custom Javascript code to the Sulu Admin UI requires a rebuild of the administration interface frontend application. According to the Sulu docs, running the following command is enough:

bin/adminconsole sulu:admin:update-build

Sadly, this did not work in our ddev setup because ddev ships with a newer version of npm. Due to a breaking change for linked packages, Sulu is not compatible with npm > 6 at the moment.

How to downgrade the npm version shipped with the standard ddev setup? There are multiple ways of doing this.

  1. You can use the ddev's hook system for running the command. In your config.yaml add the following configuration:
- exec: "npm i -g npm@6"

The downside of this approach is that the command is run every time you start your ddev environment. This can be annoying as you have to wait for quite a while until the downgrade has finished.

  1. You can extend the project's Dockerfile with the logic to downgrade npm. This will be executed just once during the image build process. Add a new file .ddev/web-build/Dockerfile to your project with the following content:
RUN npm i -g npm@6

We went for the solution to add the Dockerfile to avoid having to wait for the npm downgrade each time the ddev project gets started.

It would be beneficial to have a configuration option for ddev to install a specific version of npm. That's why we've opened an issue on GitHub.