Problems running npm install on Elastic Beanstalck - node.js

Situation
I have a Laravel (5.4) application that uses npm, bower and gulp for frontend.
I have configured all with success on deploy but the npm install or npm install --production (that in my case is the same) command give me errors and makes the deploy to fail.
Problem
Here is the "Causes" as response from AWS when i run eb deploy command.
Application update failed at 2017-06-07T17:08:38Z with exit status 1 and error: container_command 01-npm-install in .ebextensions/05-frontend-install.config failed.
npm WARN lifecycle npm is using /usr/bin/node but there is no node binary in the current PATH. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
npm WARN deprecated minimatch#2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch#1.0.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated node-uuid#1.4.8: Use uuid module instead
npm WARN deprecated minimatch#0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs#1.2.3: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs#^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
npm WARN prefer global node-gyp#3.6.2 should be installed with -g
npm WARN prefer global marked#0.3.6 should be installed with -g
> node-sass#3.13.1 install /var/app/ondeck/node_modules/node-sass
> node scripts/install.js
npm ERR! file sh
npm ERR! path sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn sh
npm ERR! node-sass#3.13.1 install: `node scripts/install.js`
npm ERR! spawn sh ENOENT
npm ERR!
npm ERR! Failed at the node-sass#3.13.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-06-07T17_08_38_740Z-debug.log.
Incorrect application version "app-5d9c-170607_190633" (deployment 40). Expected version "app-0466-170606_110037" (deployment 31).
The .ebextensions/05-frontend-install.config file has this content
container_commands:
00-npm-upgrade:
command: "npm install -g npm#latest"
01-npm-install:
command: "npm install --production"
02-gulp-install:
command: "sudo npm install gulp"
03-bower-install:
command: "sudo npm install bower"
04-bower-deploy:
command: "sudo bower install --allow-root"
05-gulp-deploy:
command: "sudo npm run prod"

Achived with an EB HOOK!
I solved my problem by using a custom elastic beanstalk post-deploy platform hook (sounds great eh?)
my 04-nodenpm.config file has this content:
container_commands:
00-entersudoi:
command: "sudo -i"
01-removeoldnode:
command: " yum remove -y nodejs npm"
02-get-noderpm:
command: " curl --silent --location https://rpm.nodesource.com/setup_7.x | bash -"
03-ensurecggmake:
command: " yum install -y gcc-c++ make"
04-installnodenpm:
command: " yum install -y nodejs"
05-exitsudoi:
command: "exit"
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99npminstall.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
cd /var/app/current/
sudo npm install -g gulp bower laravel-elixir
sudo bower install --allow-root
sudo gulp --production
The part that solved the problem is under files: where i am manually adding an /opt/elasticbeanstalk/hooks/appdeploy/post/99npminstall.sh file with content: that as a post deploy action makes the npm install ... and all the stuff i wanted.
TL;DR:
npm seems not be totally available on container_commands. Use a post deploy hook to fire those npm installation commands.
Refs & Usefull links:
http://www.eq8.eu/blogs/29-aws-elasticbeanstalk-deployment-hooks
https://forums.aws.amazon.com/thread.jspa?threadID=137136

Related

How to fix this Error -npm

I tried to install npm and I got the following error.
I already removed npm and reinstall it again, but I again got the following error:
npm ERR! Linux 4.15.0-30-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! vx-leave-system#0.0.1 start: `node ./tools/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vx-leave-system#0.0.1 start script 'node ./tools/server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vx-leave-system package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./tools/server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs vx-leave-system
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls vx-leave-system
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/seelan/Documents/vx-leave-system/npm-debug.log
How can I fix this?
On ubuntu 18.04 following steps saved me
To remove the distro-stable version, type the following:
sudo apt remove nodejs
This command will remove the package and retain the configuration files.
sudo apt purge nodejs
As a final step, you can remove any unused packages that were automatically installed with the removed package:
sudo apt autoremove
Refresh your local package index by typing:
sudo apt update
Enable the NodeSource repository by running the following command
(optinal) If you need to install another version, for example 14.x, just change setup_12.x with setup_14.x
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
Once the NodeSource repository is enabled, install Node.js and npm by typing:
sudo apt install nodejs
Verify that the Node.js and npm were successfully installed by printing their versions:
node --version (v12.18.4)
npm --version (6.14.6)
It seems to me that you're running a newer version of Node, but an outdated version of NPM.
You can do either of the following:
Try the latest stable version of NPM:
You can upgrade to the latest version of npm using: npm install -g npm#latest
Uninstall Node form your machine completely, go to their website and install the latest stable Node version. NPM comes with it.
I faced this issue too today and the problem was caused by an upgrade in my node and npm version. Guess my project dependencies were still running on older versions of node and npm
I fixed it by deleting the node_modules folder and run
npm install
I hope this helps
This looks like a permissions issue in your home directory. To reclaim ownership of the .npm directory execute:
sudo chown -R $(whoami) ~/.npm
Check the updates of dependencies
npm outdate
Run the next command to update dependencies
npm update
Remove the path folder directory C:\Users\ACER\AppData\Local**\npm-cache_logs\2021-12-29T13_41_22_984Z-debug-0.log**
and then run this command in your CLI npm install -g npm#latest
this works with you

npm ERR! code ENOLOCAL

after making a software to my laptop I installed all the programs includes node js
my OS windows
$ node -v
v8.11.1
and the npm
$ npm -v
v5.6.0
when I tried to install npm globally it's gave me this error :
$ npm install -g
npm ERR! code ENOLOCAL
npm ERR! Could not install from "" as it does not contain a package.json
file.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Aroma\AppData\Roaming\npm-cache\_logs\2018-04-
07T11_10_29_184Z-debug.log
or even when I tried to install it locally to a repository it's gave me:
$ npm install
npm WARN saveError ENOENT: no such file or directory, open
'C:\Users\Aroma\Desktop\app\package.json'
npm notice created a lockfile as package-lock.json. You should commit this
file.
npm WARN enoent ENOENT: no such file or directory, open
'C:\Users\Aroma\Desktop\app\package.json'
npm WARN app No description
npm WARN app No repository field.
npm WARN app No README data
npm WARN app No license field.
up to date in 0.11s
any help would be appreciated
Try this command to change the npm version: npm -g install npm#4.2.0 it works for me on this issue.
I had same problem. I solved in this way.
Step 1: Open the command prompt as an Administrator and run npm install -g create-react-app to solve the npx issue.
Step 2: run npx create-react-app your-app-name
I got the same issue.
What I did was to rename the package-lock.json by:
mv package-lock.json package.json
, and then this issue should be solved.
If you get the next issue of showing a message:
[...] / rollbackFailedOptional: verb npm-session xxxxxxxxxxx
, then you could do
sudo npm config rm proxy
sudo npm config rm https-proxy
sudo npm install npm#latest -g
These steps works for me.
Hope they could be helpful to you too.

How to solve npm ERR! code ERR_INVALID_OPT_VALUE

I went to install nodejs and npm on Debian9 like this with the root account because npm is not included in the legacy debian package :
curl -sL https://deb.nodesource.com/setup_8.x | bash -
.../...
## Run `apt-get install nodejs` (as root) to install Node.js v8.x and npm
:~#
:~# apt-get install -y nodejs
Now I would like to install some module with npm or to do the update of npm and I've got this error message
:~# npm cache clean -f
npm WARN using --force I sure hope you know what you are doing.
:~# npm install -g npm
npm ERR! code ERR_INVALID_OPT_VALUE
npm ERR! The value "4294967295" is invalid for option "family"
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-03-29T11_17_37_357Z-debug.log
Here the link to the debug log file : Justpasteit
Thanks for any help

How do I solve these errors with npm install and sudo npm install -g harp?

I was trying to install Node.js, Grunt and Harp so I downloaded Node.js and then I wrote in the terminal this (note: I also had Homebrew):
node -v
npm update -g npm
npm install -g grunt-cli
After that I installed Bootstrap files and I wrote (always from the terminal) I wrote:
npm install
the terminal returned this:
[bash-3.2# npm install
npm WARN saveError ENOENT: no such file or directory, open '/Users/Bimbi/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/Bimbi/package.json'
npm WARN Bimbi No description
npm WARN Bimbi No repository field.
npm WARN Bimbi No README data
npm WARN Bimbi No license field.
up to date in 0.05s
After that I ran these commands to update Ruby, install bundler and some dependencies:
\curl -sSL https://get.rvm.io | bash -s stable
rvm list known
rvm install ruby-2.4.2
ruby -v
rvm use ruby-2.4.2 —default
gem install bundler
bundler -v
gem init
bundle install
gem install Jekyll bundler
then I tried to install harp:
sudo npm install -g harp
the terminal returned this:
npm WARN deprecated connect#2.30.2: connect 2.x series is deprecated
npm WARN deprecated graceful-fs#3.0.11: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated coffee-script#1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
/usr/local/bin/harp -> /usr/local/lib/node_modules/harp/bin/harp
+ harp#0.25.0
updated 1 package in 9.639s
after this message I ran:
harp -V
the console returned:

Unable to upgrade npm from 1.4.28 to latest (2.2)

I'm using stable version of node on Ubuntu 14.04. (installed via PPA) When I was trying to upgrade some packages like yo, I got the error below:
npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your version of node/npm: yo#1.4.2
npm ERR! notsup Required: {"node":">=0.10.0","npm":">=2.1.0"}
npm ERR! notsup Actual: {"npm":"1.4.28","node":"0.10.35"}
npm ERR! System Linux 3.13.0-32-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "update" "-g"
npm ERR! cwd /home/ekrem
npm ERR! node -v v0.10.35
npm ERR! npm -v 1.4.28
npm ERR! code ENOTSUP
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ekrem/npm-debug.log
npm ERR! not ok code 0
When I hit (sudo) npm update -g npm, here's the result I got:
npm#2.1.3 /home/ekrem/.node/lib/node_modules/ionic/node_modules/npm
After hitting npm -v
1.4.28
I've also cleared all files under ~/.npm, cleared cache, reinstall components I needed but nothing changes. In addition;
➜ ~ which node
/usr/bin/node
➜ ~ which npm
/usr/bin/npm
➜ ~ less ~/.npmrc
prefix = ~/.node
I've checked similar issues on the net but there's nothing close to mine.
UPDATE:
I've removed nodejs; cleared files under ~/.node & ~/.npm (as #johns has suggested) installed using first method of the instructions here. Here are updated outputs:
➜ node -v
v0.10.35
➜ npm -v
1.4.28
➜ which node
/home/ekrem/local/bin/node
➜ which npm
/home/ekrem/local/bin/npm
➜ npm update -g npm
# returns nothing
➜ ~ npm config get prefix
/home/ekrem/.node
I was facing a similar issue and found this post. The way I got npm to work after several tries is to remove all the npm 'node_module' folders and delete any npm config files particularly the .npmrc file in your home directory.
Then I ran 'sudo apt-get purge nodejs'.
I went to the installer and reinstalled nodejs using the following:
'curl https://npmjs.org/install.sh | sh'
then ran:
sudo apt-get install nodejs
Finally I ran:
npm update -g npm
There were issues posted about a bug in that 'update' function, but it seemed to work for me and I got from 1.4 to 2.7.
I hope this saves someone some time.
This solution worked for me
navigate to C:\Program Files (x86)\nodejs with cmd.exe and then run the installation without -g:
npm install npm
In my case I had to do the following steps to go from npm#1.4.28 to npm#3.2.0 (currently the latest):
curl -L https://www.npmjs.org/install.sh | sudo sh
This line may trigger some errors like:
Error: EACCES, mkdir '/usr/lib/node_modules/npm'
If so, simply run:
sudo rm -rf /usr/lib/node_modules/npm (or the specified directory display in the error)
From there:
sudo npm install -g npm#3.0-latest
And now the
npm -v
successfully display a beautiful: 3.2.0
There are a lot of comments out there about "npm update -g" being broken and to not use it for now:
https://github.com/npm/npm/issues/6247
I'd trying resetting or reinstalling npm and then go from there - a fresh reinstall of npm should be relatively painless and fix things:
https://github.com/npm/npm/wiki/Troubleshooting#if-your-npm-is-broken
Similar answer to #ThinkBonobo, but all I had to do was run the update straight from npmjs.org. From a freshly provisioned instance:
$curl -sL https://deb.nodesource.com/setup | sudo bash -
$sudo apt-get install nodejs
$npm -v
1.4.28
$curl -L https://npmjs.org/install.sh | sudo sh
$npm -v
2.7.3
No other steps were requried.

Resources