Can’t generate build.sh for node project?

I’m trying to test my .travis.yml file locally before pushing commits publicly, but I can’t get language: node_js to spit out a build.sh file. Other languages appear to work, so it appears to be specifically node_js that’s the problem, but the error message is…not the least bit helpful.

What am I doing wrong here?

$ docker run --privileged --name travis -it travisci/ubuntu-ruby:18.04 /bin/bash -l
$ adduser travis
$ usermod -aG sudo travis
$ apt-get install sudo
$ su - travis
$ mkdir -p /home/travis/builds
$ cd /home/travis/builds
$ git clone https://github.com/travis-ci/travis-build.git
$ cd travis-build
$ mkdir -p /home/travis/.travis
$ ln -s $(pwd) /home/travis/.travis/travis-build
$ gem install bundler
$ bundle install --gemfile ~/.travis/travis-build/Gemfile
$ bundle update travis
$ bundler binstubs travis

$ cd ~/karanlyons/murmurHash3.js

$ cat .travis.yml
sudo: false
language: node_js
node_js:
  - node
  - lts/*
cache: yarn

$ ~/.travis/travis-build/bin/travis version
1.8.10

$ cat ~/.travis/config.yml
---
last_check:
  etag: '"c71cbe18761a9dd51b165114df50e6dc"'
  version: 1.8.10
  at: 1577934780
checked_completion: true
completion_version: 1.8.10

$ ~/.travis/travis-build/bin/travis compile
E NoMethodError: undefined method `downcase' for nil:NilClass
/home/travis/builds/travis-build/lib/travis/build/script/node_js.rb:238:in `is_win?'
/home/travis/builds/travis-build/lib/travis/build/script/node_js.rb:242:in `setup_os'
/home/travis/builds/travis-build/lib/travis/build/script/node_js.rb:23:in `setup'
/home/travis/builds/travis-build/lib/travis/build/stages/builtin.rb:12:in `block in run'
/home/travis/builds/travis-build/lib/travis/shell/builder.rb:194:in `with_options'
/home/travis/builds/travis-build/lib/travis/build/stages/base.rb:15:in `with_stage'
/home/travis/builds/travis-build/lib/travis/build/stages/builtin.rb:8:in `run'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:131:in `block in run_stage'
/home/travis/builds/travis-build/lib/travis/shell/builder.rb:145:in `trace'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:130:in `run_stage'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:120:in `define_stage'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:86:in `block in run'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:85:in `each'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:85:in `run'
/home/travis/builds/travis-build/lib/travis/build/script.rb:242:in `run'
/home/travis/builds/travis-build/lib/travis/build/script.rb:148:in `sexp'
/home/travis/builds/travis-build/lib/travis/build/script.rb:127:in `compile'
/home/travis/.travis/travis-build/init.rb:51:in `run'
/var/lib/gems/2.4.0/gems/travis-1.8.10/lib/travis/cli/command.rb:198:in `execute'
/var/lib/gems/2.4.0/gems/travis-1.8.10/lib/travis/cli.rb:64:in `run'
/var/lib/gems/2.4.0/gems/travis-1.8.10/bin/travis:18:in `<top (required)>'
/home/travis/.travis/travis-build/bin/travis:29:in `load'
/home/travis/.travis/travis-build/bin/travis:29:in `<main>'
E /home/travis/builds/travis-build/lib/travis/build/script/node_js.rb:238:in `is_win?'
/home/travis/builds/travis-build/lib/travis/build/script/node_js.rb:242:in `setup_os'
/home/travis/builds/travis-build/lib/travis/build/script/node_js.rb:23:in `setup'
/home/travis/builds/travis-build/lib/travis/build/stages/builtin.rb:12:in `block in run'
/home/travis/builds/travis-build/lib/travis/shell/builder.rb:194:in `with_options'
/home/travis/builds/travis-build/lib/travis/build/stages/base.rb:15:in `with_stage'
/home/travis/builds/travis-build/lib/travis/build/stages/builtin.rb:8:in `run'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:131:in `block in run_stage'
/home/travis/builds/travis-build/lib/travis/shell/builder.rb:145:in `trace'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:130:in `run_stage'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:120:in `define_stage'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:86:in `block in run'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:85:in `each'
/home/travis/builds/travis-build/lib/travis/build/stages.rb:85:in `run'
/home/travis/builds/travis-build/lib/travis/build/script.rb:242:in `run'
/home/travis/builds/travis-build/lib/travis/build/script.rb:148:in `sexp'
/home/travis/builds/travis-build/lib/travis/build/script.rb:127:in `compile'
/home/travis/.travis/travis-build/init.rb:51:in `run'
/var/lib/gems/2.4.0/gems/travis-1.8.10/lib/travis/cli/command.rb:198:in `execute'
/var/lib/gems/2.4.0/gems/travis-1.8.10/lib/travis/cli.rb:64:in `run'
/var/lib/gems/2.4.0/gems/travis-1.8.10/bin/travis:18:in `<top (required)>'
/home/travis/.travis/travis-build/bin/travis:29:in `load'
/home/travis/.travis/travis-build/bin/travis:29:in `<main>'
echo -e ""
echo -e "There was an error in the .travis.yml file from which we could not recover.
"
echo -e "Unfortunately, we do not know much about this error."
echo -e ""
echo -e "Please review https://docs.travis-ci.com"
exit 2

config[:os] seems to be nil for some reason, but I don’t see any way to fix that myself.

Oh, so I have to define os: linux in my config? My understanding was that was optional.

This is the corresponding line: https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/script/node_js.rb#L238.
From it, you can see that you are missing the os: key.

In reality, travis compile is run on a preprocessed .travis.yml with stuff like default values inserted. So things like this can happen.

Ah, okay, is there more documentation on this? I’m running into additional issues now:

$ ./compile.sh
Build system information
Build language: node_js
Build id: ''
Job id: ''
Runtime kernel version: 4.14.154-boot2docker

Timeout waiting for network availability.
tee: /etc/initramfs-tools/update-initramfs.conf: No such file or directory
tee: /etc/docker/daemon.json: No such file or directory
docker: unrecognized service

$ cd karanlyons/murmurHash3.js

$ nvm install node
/home/travis/.travis/functions: line 109: nvm: command not found
Failed to install node. Remote repository may not be reachable.
Using locally available version node, if applicable.
$ nvm use node
/home/travis/.travis/functions: line 109: nvm: command not found
Unable to use node
The command "false" failed and exited with 1 during .

Your build has been stopped.

L109 is just eval "${cmd} ${secure}”, and if I try eval “nvm install node” things appear to work fine. nvm is not an executable, so I wonder if things aren’t getting sourced properly, i.e., there’s yet more preparation that’s meant to be done here.

The main documentation on travis-build is its README. As it says, the resulting script is designed to be run on Travis builders (with corresponding preinstalled software) and shouldn’t be run on regular machines since it makes irreversible changes to the system.

Travis used to have Docker containers mimicking their builders but they don’t do that anymore (but the old containers are still available). The closest thing they publish that I know of is https://github.com/travis-ci/travis-cookbooks/.

Yeah, I was a bit worried that was where we were going to end up. I was hoping not to have to spin up a whole bunch of local infra to just test out this build, so I’ll probably have to take a different tack. But thank you for your help!