Using nvm to run gulp with node 12.x with sage 8

Hi there,

I have a site I created 2 years ago with trellis/bedrock/sage8.x that is running on production.
Now I tried to update everything, using a Linux 16.04 (in DigitalOcean) and updating trellis and bedrock to the current versions. I haven’t updated the sage installation.

I have the deploys running fine but for this problem: runnning ‘gulp --production’ on the server produces sass related problems.

In my local machine, I use nvm to set my node to 0.12.8 and this command runs perfectly (and my dev environment reflects it). Any try to update node to a newest version gets me into a rabbit hole of errors related to the version of gulp-sass, node-sass and more issues that I am not able to overcome.

My current approach is to try to install nvm and have the server run node 0.12 in order to be able to run gulp --production safely.

I have followed the advice of @strarsis on Theme main.css: Cache busting and I came up with:

an .nvmrc file with:

v0.12.8

a build-before file with:

- name: Use specific node version
  shell: . $NVM_DIR/nvm.sh && nvm install && nvm use
  connection: local
  args:
  chdir: "{{ project.local_path }}/web/app/themes/sage"

# Paths
- shell: . $NVM_DIR/nvm.sh && dirname $(nvm which | tail -1)
  connection: local
  args:
  chdir: "{{ project.local_path }}/web/app/themes/sage"
  register: nvm_which

- name: Clean npm cache
  command: npm cache clean --force
  connection: local
  args:
  chdir: "{{ project.local_path }}/web/app/themes/sage"

- name: Clean npm prev install
  command: rm -rf node_modules
  connection: local
  args:
  chdir: "{{ project.local_path }}/web/app/themes/sage"

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

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

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

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

- name: Copy project local files
  synchronize:
  src: "{{ project.local_path }}/web/app/themes/sage/dist"
  dest: "{{ deploy_helper.new_release_path }}/web/app/themes/sage"
  group: no
  owner: no
  rsync_opts: --chmod=Du=rwx,--chmod=Dg=rx,--chmod=Do=rx,--chmod=Fu=rw,--chmod=Fg=r,--chmod=Fo=r

However, the gulp --production command doesn’t work properly, showing some sass-related problems.

I have tried several things to check if the server is actually running nvm and the 0.12 version of node, but I can’t figure it out, as some commands fail and others don’t give me any feedback.

My questions are:

  • How do I know the server is actually using node 0.12.8?
  • How can I make it use that node version?

Thanks a lot!

1 Like

The build is done on the workstation / ansible control machine (ssh client) - not on production (server).
The build artifacts are then transferred to production (server) using rsync.

*The production system should be as lean as possible.

1 Like

Oh, I see. That explains other things I was seeing, thanks!

Do you know how could I make it use node 0.12 there?

nvm use (without extra arguments) looks for a .nvmrc file (in theme project folder).
You can hence create a .nvmrc file with the contents ‘0.12’ and
nvm should use it like a nvm use 0.12 invocation.

Thanks @strarsis,

The nvm setup was right, and it was using node 0.12 properly.

My problem was that my npm setup stopped working when removing the node_modules folder and doing it again, so it was my fault there.

For reference, I ended updating to node 4.5 and had sage8 working fine.

Thanks!

New, improved and shorter approach to use a specific node version using nvm when building the theme during Trellis deploy:

1 Like