npmcommand-line-interfacehubspotddev

Why do I have to re-install HubSpot's CLI under DDEV every time it restarts?


I'm working on a custom HubSpot theme for a client, making changes locally and using the HS CLI to watch and upload any changes it sees. I'm also under Windows, so I'm using DDEV under WSL 2 for the server environment.

If I go to the project directory and type:

$ ddev npm install -g @hubspot/cli
$ ddev exec hs watch my-theme my-theme

Everything works fine... the HS CLI monitors for changes, uploads them, and all's well.

Then when I'm done for the day, I press CTRL+C to exit the CLI, and type ddev stop to shut down that site.

The next day (or even immediately after), I type:

$ ddev start
$ ddev exec hs watch my-theme my-theme

...and get this error:

bash: line 1: hs: command not found
Failed to execute command hs watch my-theme my-theme: exit status 127

The only way to fix it is if I install the HubSpot CLI under DDEV again:

$ ddev npm install -g @hubspot/cli

What gives? What am I doing wrong?

EDIT: I should note that the entirety of the package.json is this:

{
  "dependencies": {
    "@hubspot/cli": "^4.1.7"
  }
}

Solution

  • The problem here is that you're installing @hubspot/cli globally in the web container, so it will likely go into /usr/local, which is transient (it's created from the docker image each time the project is started).

    You should instead do this in a .ddev/web-build/Dockerfile, so it gets built once and added onto the docker image your project uses:

    RUN npm install -g @hubspot/cli
    

    You could also install it into the project instead of installing it globally and it would persist with your project.

    Docs on Dockerfile usage are at https://ddev.readthedocs.io/en/latest/users/extend/customizing-images/#adding-extra-dockerfiles-for-webimage-and-dbimage