Deploy fails on npm install

I am attempting to deploy some local changes to production and getting an error that is especially unusual to me. I don’t know where to begin in trouble shooting it but I know I don’t know which environment it’s referring to. And since I rely on Trellis to provision my server I don’t know why a package version error would prevent a deploy.

Here’s how I would approach this. I would take a look in your project’s Trellis code for the Run npm install task that failed, to understand what it is doing. You’re probably using this version of the build-before.yml file.

 - name: Run npm install
   command: npm install
   connection: local
   args:
     chdir: "{{ project.local_path }}/web/app/themes/sage"

It cds (chdir) into your local machine’s theme directory in your local_path and runs the specified command: npm install. The connection: local means that this command will be run on the local machine, not the server.

Now that we understand what is happening, we can try a common troubleshooting technique: “manually run the command where Ansible failed.” Try running npm install on your local machine in your theme directory. You’ll probably see the same warning messages, but hopefully this will give even more info and you’ll get to troubleshoot with Ansible out of the picture.

This appears to be just an issue of npm install on your local machine, not really an issue with Trellis code. Trellis assumes you’ve worked out successful theme asset build on your local machine. The build-before.yml file is just an example of how you can create your own tasks to build your theme assets, if desired.

You may want to see these classic NPM Dubugging Guidelines. For example, it mentions “Do not use sudo with npm.” If you use sudo with npm, it could cause all sorts of troubles, but also note that the Trellis command above isn’t using sudo with npm install. If somehow you must use sudo, you may need to add sudo to the command, or add become: true to the task.

If you can’t get the manual npm install to work at all, you could comment out the associated task (and maybe the bower task) in build-before.yml and just leave the gulp and sync tasks. That might help you get a successful deploy for the short term, but of course you’ll want to sort out your npm issues in the long term. If none of those tasks work. in a pinch you could just comment them out and sync up your built theme assets manually using rsync.

Okay thank you! I will try this out and report back my result.

Thanks for the reply.

I read your post, and the NPM Debugging Guidelines.

I see one issue. The official documentation to install NodeJS, which I understand also installs NPM at the same time, advises me to install NodeJS using sudo.

Attempting to install it without using sudo results in an error and failure to install.

I am about to start development on two other website projects so I would prefer to resolve this issue permanently rather than the stop-gap you recommended. But I appreciate the alternative! :slight_smile:

As for running npm install manually I get this output.

What am I missing here?

Can you post the contents of your theme’s package.json?

I don’t have expertise with node.js or npm. I would be in the same position of having to research carefully how to install on your particular system, so I’ll have to leave you to it. I’d My best advice would be to follow the counsel in NPM Debugging Guidelines:

Use nvm to manage node versions

nvm installs node in your user’s home directory without needing superuser privileges. It also allows you to toggle between versions of node effortlessly.

:star: Have you tried nvm? It works well for me.


If you’ve determined you must use sudo, I’m not sure there’s value in trying to debug your latest npm install output that doesn’t use sudo.

:arrow_up: The implication is: Try adding sudo or the become parameter to the relevant commands in your build-before.yml.
:star: Have you tried the above? You’d need to get a manual sudo npm install working first.


Node.js and npm being used across the dev industry, issues with them are less about Sage and Trellis and more about setting up a reliably functioning development environment. One implication is that forums more general than Roots discourse may help.

I don’t have additional knowledge to be of any more help on this thread. But I want to empathize that issues such as this can be frustrating. I still feel like a total newb on the topic of my local development environment (e.g., including node/npm). At times I run into inexplicable problems or spend hours and days getting things set up or modified.

I think the fact that users manage to provide quick answers on this and any forum obscures the reality of how hard-earned the knowledge actually is. As a dev I often think “I should just know this,” or “this should just work.” But I suspect that the reality is that others have a similar experience to my own, often spending days at a time resolving a single difficult issue. The consolation is that the more familiarity and understanding you work to develop on each trial, the faster your make it through subsequent iterations with your dev environment.

1 Like

While working on resolving this today it occurred to me that the most recent (and only) Sage Theme I built was on my Mac. So I never encountered the note about installing NodeJS using sudo.

I completely reinstalled my Linux Ubuntu GNOME OS and dove straight into setting up this particular site I’m currently working on to see if I got any different result.

So I researched nvm and discovered that it specifically installs NodeJS / NPM without using sudo. I followed these instructions specifically and was successful in doing that.

Then I re-ran npm install in my Theme directory and it ran successfully without error.

So then I went back to run my deploy (the original issue) and I get this.

So, I can’t exactly say this issue is resolved because I am getting stopped immediately after running my deploy. But npm install is working so I’m assuming if I resolve this issue then this topic will be able to be resolved.

Yep, here’s my package.json.