Whilst trying to manually compile a program from source code, one of the steps is to use gulp to concatenate CSS and JavaScript files.
However when I tried this, I ran into the following error:
ck@mintp ~/Git/app $ gulp -f gulpfile.js
ReferenceError: primordials is not defined
at fs.js:45:5
at req_ (/home/ckadm/Git/invoiceninja/node_modules/natives/index.js:143:24)
at Object.req [as require] (/home/ckadm/Git/invoiceninja/node_modules/natives/index.js:55:10)
at Object.<anonymous> (/home/ckadm/Git/invoiceninja/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
According to this Stackoverflow question, the problem is caused by an incompatibility between gulp 3.x and newer Node.js versions.
The gulp command above was run with gulp-cli 2.3.0 and gulp 3.9.1 in the application directory:
ck@mintp ~/Git/app $ gulp --version
CLI version: 2.3.0
Local version: 3.9.1
Node.js at this point was installed with 14.15.4:
ck@mintp ~/Git/app $ node -v
v14.15.4
The same Stackoverflow question mentions to either upgrade to gulp 4.x or downgrade node.js to version 11.
I decided to do the latter and be able to switch between node.js versions in the future. node.js 11.15.0 was downloaded, unpacked and the binary copied to /usr/local/bin/node-11.15.0. Then the previous alternatives configuration (pointing to node 14.15.4) was removed. And finally, the new alternatives link was set by using update-alternatives --install, pointing to /usr/local/bin/node-11.15.0:
ck@mintp ~/tmp $ wget https://nodejs.org/download/release/v11.15.0/node-v11.15.0-linux-x64.tar.gz
ck@mintp ~/tmp $ tar -xzf node-v11.15.0-linux-x64.tar.gz
ck@mintp ~/tmp $ cd node-v11.15.0-linux-x64/
ck@mintp ~/tmp/node-v11.15.0-linux-x64 $ sudo cp -p bin/node /usr/local/bin/node-11.15.0
ck@mintp ~/tmp/node-v11.15.0-linux-x64 $ sudo update-alternatives --remove node /usr/local/bin/node
ck@mintp ~/tmp/node-v11.15.0-linux-x64 $ sudo update-alternatives --install /usr/bin/node node /usr/local/bin/node-11.15.0 1 --force
ck@mintp ~ $ node --version
v11.15.0
Note: Also see older article Installing a newer node.js and npm version on Debian 10 (Buster) using update-alternatives.
With Node.js running as version 11.15.0, the gulp command executed successfully:
ck@mintp ~/Git/app $ gulp -f gulpfile.js
[11:34:40] Using gulpfile ~/Git/app/gulpfile.js
[11:34:40] Starting 'all'...
[11:34:40] Starting 'styles'...
[11:34:41] Finished 'styles' after 90 ms
[11:34:41] Starting 'styles'...
[11:34:41] Finished 'styles' after 37 ms
[11:34:41] Starting 'styles'...
[11:34:41] Finished 'styles' after 12 ms
[11:34:41] Starting 'styles'...
[11:34:41] Finished 'styles' after 4.02 ms
[11:34:41] Starting 'styles'...
[11:34:41] Finished 'styles' after 11 ms
[11:34:41] Starting 'styles'...
[11:34:41] Finished 'styles' after 3.67 ms
[11:34:41] Starting 'styles'...
[...]
[11:34:41] Finished 'default' after 9.16 ms
ck from Switzerland wrote on Jan 27th, 2022:
Hi Sunil. Unfortunately not. In my case the application (Invoice Ninja v4) was created with very specific versions as dependencies. It might depend on the application build process, but you probably need to switch the node version. Unless you find a way to fix the gulp error with gulp itself? Good luck!
Sunil from India wrote on Jan 27th, 2022:
Can we do it without compromising on the node version?
I wanted to use node v14x
below are my other versions required:
gulp -v
CLI version: 2.3.0
Local version: 3.9.1
npm -v
6.14.15
node -v
v14.18.3
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder