Issue
Context of Error
I am launching an EC2 instance (Linux PHP platform). During the build, I install npm successfully as well as an unrelated package PM2.
However after that it tries to install laravel-echo-server using npm i -g laravel-echo-server
and it always returns an error:
$ npm i -g laravel-echo-server
/usr/bin/laravel-echo-server -> /usr/lib/node_modules/laravel-echo-server/bin/server.js
> [email protected] postinstall /usr/lib/node_modules/laravel-echo-server/node_modules/spawn-sync
> node postinstall
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn sh
npm ERR! file sh
npm ERR! path sh
npm ERR! errno -2
npm ERR! [email protected] postinstall: `node postinstall`
npm ERR! spawn sh ENOENT
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Attempts at Resolving
The weird thing is it works completely fine when I SSH into the instance after build and run the command myself. It is only when the .ebextensions build tries to call it that it fails.
npm config set scripts-prepend-node-path true #to make sure it has the right node path
sudo ln -s `which nodejs` /usr/bin/node #to create a sym link to the node location
sudo ln -s /usr/bin/node /usr/bin/nodejs #another attempt to create a sym link to the node location
Additional Info
.ebextensions script
sudo yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_13.x | sudo -E bash -
sudo yum install -y nodejs
npm install -g pm2@latest
npm install -g laravel-echo-server
which node
/usr/bin/node
which nodejs
not found #or /usr/bin/nodejs if I create the symlink, but that doesn't help
which pm2
/usr/bin/pm2
Solution
Apparently it was a problem with spawn sync, so I changed it to this and it worked succesfully:
npm i -g laravel-echo-server --ignore-scripts spawn-sync
Answered By - famouspotatoes