Installing git through .ebextensions on Elastic Beanstalk - node.js

I'm getting an error deploying to Elastic Beanstalk, because there is no git on the instance. One of the dependencies in my package.json is dependant on a git repository and needs to git clone.
Git is not installed on the instances. I tried installing it through .ebextensions .conf file while deploying, through yum, but when I ssh into the instance it's not there.
Question is: what is the correct way to install and have git on a Linux instance running on Elastic Beanstalk before npm install is called on that instance?
Here's the log showing the error:
[2015-04-18T09:00:02.815Z] ERROR [1777] : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError)
caused by: + /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
npm WARN package.json amity-api-v2#2.0.0 No repository field.
npm WARN package.json amity-api-v2#2.0.0 No README data
npm WARN `git config --get remote.origin.url` returned wrong result (https://github.com/awslabs/dynamodb-document-js-sdk) undefined
npm WARN `git config --get remote.origin.url` returned wrong result (https://github.com/awslabs/dynamodb-document-js-sdk) undefined
npm ERR! git clone https://github.com/awslabs/dynamodb-document-js-sdk undefined
npm ERR! git clone https://github.com/awslabs/dynamodb-document-js-sdk undefined
npm ERR! Linux 3.14.35-28.38.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v0.12.0-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.12.0-linux-x64/bin/npm" "--production" "install"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code ENOGIT
npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.

If you put a config file in your .ebextensions folder like this:
packages:
yum:
git: []
Make sure the git package is in a config file with a higher execution index then one that actually requires git. It is common to have it in a first config file named: 00-packages.config.

I can think of three ways you could ensure git(or any dependency) is installed on the system before npm install is run.
Define a preinstall script in your package.json that installs git if required.
You can add a script(file), using ebextensions in either the pre-appdeploy hooks directory, or the preinit hooks directory. I would suggest the preinit hook, as that's where the hook for installing packages is. Just set the path of your script to /opt/ebextensions/hooks/preinit/99_install_git.sh, or if you want to do in pre-appdeploy, /opt/ebextensions/hooks/appdeploy/pre/99_install_git.sh, and make the file executable by using the mode field.
Using ebextensions to install a package.
For your use case, I think #3 is the best option. Kinda late, but I hope you find it useful

Related

Issue with git dependency on node version upgrade

I am running a VUE.JS app in a Docker container. The app is currently using node 14.19.0, but I tried upgrading the version to node 15/16.
After changing the node version in the Dockerfile and updating some of the devDependencies, I get an NPM error:
npm ERR! npm ERR! An unknown git error occurred
npm ERR! npm ERR! command git --no-replace-objects ls-remote ssh://git#github.com/[NAMESPACE_PLACEHOLDER]/[REPO_PLACEHOLDER].git
npm ERR! npm ERR! Warning: Permanently added 'github.com' (ECDSA) to the list of known hosts.
npm ERR! npm ERR! git#github.com: Permission denied (publickey).
npm ERR! npm ERR! fatal: Could not read from remote repository.
npm ERR! npm ERR!
npm ERR! npm ERR! Please make sure you have the correct access rights
npm ERR! npm ERR! and the repository exists.
In my package.json file, the repo is loaded with https, not ssh:
"package-name-placeholder": "https://github.com/[NAMESPACE_PLACEHOLDER]/[REPO_PLACEHOLDER].git#v0.1.15"
This exact method is working with Node 14.19.0. I read that there might be an issue with trailing slashes. I tried using them, but the error persists.
Have anyone managed to do something about a similar issue?
Thanks.
Try in your Dockerfile a:
RUN git config --global url."https://${GIT_ACCESS_TOKEN}#github.com".insteadOf "ssh://git#github.com"
(If those repositories are public, you do not need the ${GIT_ACCESS_TOKEN}# part: it would be an ARG GIT_ACCESS_TOKEN passed with a docker build --build-arg GIT_ACCESS_TOKEN=xxx)
You can see here this was reported before:
npm version change in alpine-16's image, and I'm pretty sure that this problem is related to npm version.

No url found for submodule path 'bass' when using a fork of dapp-core

How can I use my fork of dapp-core in my dapp-core-template, please?
When I type
npm install git+https://github.com/MyUserName/dapp-core.git#development
I get the following error
npm ERR! code 128
npm ERR! Command failed: git submodule update -q --init --recursive
npm ERR! fatal: No url found for submodule path 'bass' in .gitmodules
What do I do wrong, please?
I tried to
I delete package-lock.json and node_modules
I got the same error while installing the package directly npm install git+https://github.com/ElrondNetwork/dapp-core.git
Some useful informations
The package I forked: https://www.npmjs.com/package/#elrondnetwork/dapp-core

Why "npm install -g grunt-cli" doesn't work correctly?

I am having trouble using grunt in my projects. I am setting up an macos computer with version 11.0.1.
The project files (local) are in principle correct, since I use it on another computer and it works fine there.
I have been trying to solve this error for more than two days, the problem is that the local configuration does not work correctly, since I get the message ~ bash: grunt command not found when trying to initialize grunt with the grunt or grunt watch command
When trying to install grunt-cli globally I get this error:
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path /Users/bertanicolau/.npm-packages
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, lstat '/Users/bertanicolau/.npm-packages'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/bertanicolau/.npm/_logs/2020-11-23T17_06_23_295Z-debug.log
The .npm-packages folder does not exist in this location, instead the .npm folder does exist, I don't know why it is looking for another.
I've tried clearing the npm cache, I've also tried deleting the package-lock.json file and changing paths on .bash-profile but none of this seems to work.
Can it be a npm or node version bug?
$ npm -v && node -v
7.0.8
v15.2.1
Thanks!
In one of your .npmrc files, you probably have prefix=/Users/trott/.npm-packages. If so, leave it and create the directory with mkdir ~/.npm-packages. Or set it to a different directory. Or remove the entry entirely.
The places to look for the .npmrc file that may be causing this to happen:
per-project config file (/path/to/my/project/.npmrc)
per-user config file (~/.npmrc)
global config file ($PREFIX/etc/npmrc)
npm builtin config file (/path/to/npm/npmrc)

NPM fails to install types

I have a problem with npm install, in that it won't install #types.
This works fine
npm install --save lodash
However asking for types does not
npm install --save #types/lodash
PS C:\Development\Temp> npm install --save #types/lodash
npm WARN `git config --get remote.origin.url` returned wrong result (git://github.com/types/lodash)
npm WARN `git config --get remote.origin.url` returned wrong result (git#github.com:types/lodash)
npm ERR! git clone git#github.com:types/lodash Cloning into bare repository 'C:\Users\myuser\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-lodash-9eb5372a'...
npm ERR! git clone git#github.com:types/lodash Host key verification failed.
npm ERR! git clone git#github.com:types/lodash fatal: Could not read from remote repository.
npm ERR! git clone git#github.com:types/lodash
npm ERR! git clone git#github.com:types/lodash Please make sure you have the correct access rights
npm ERR! git clone git#github.com:types/lodash and the repository exists.
npm ERR! addLocal Could not install types/lodash
npm ERR! Error: ENOENT: no such file or directory, stat 'C:\Development\Temp\types\lodash'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Windows_NT 10.0.15063
npm ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\ProgramData\\chocolatey\\lib\\npm\\tools\\node_modules\\npm\\bin\\npm-cli.js" "install" "--save" "#types/lodash"
npm ERR! cwd C:\Development\Temp
npm ERR! node -v v8.6.0
npm ERR! npm -v 1.4.9
npm ERR! path C:\Development\Temp\types\lodash
npm ERR! syscall stat
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Development\Temp\npm-debug.log
npm ERR! not ok code 0
PS C:\Development\Temp>
This has got me scratching my head. I've updated Chocolatey, NodeJS, NPM to make sure their own the latest versions. Tried the commands on empty folders or an existing TypeScript project - thinking it might be getting confused being ran within a Git repository (error: remote.origin.url). Looking at the GitHub URL it makes no sense git://github.com/types/lodash
I took these examples from MSDN Blog - The Future of Declaration Files
Update: I've uninstalled Node.js and tried reinstalling v6.11.3 LTS or v8.6.0. However the #types command still fails.
Update 2: I've realised Chocolately was masking the npm version. I removed the Chocolately folder, and upgraded npm as per #Louis answer.
Upgrade your npm version to version 4 or 5. I'm mentioning 4 because I ran into problems with 5, and using 4 is still viable. I don't know of any good reason to run an older version.
You are using npm version 1.4.9, as shown in this line of the log:
npm ERR! npm -v 1.4.9
The problem is that npm versions prior to version 2 do not support scoped packages. Packages that begin with an # are scoped packages, so #types/lodash is a scoped package. You need npm version 2 or greater to install it. If you were to use the latest npm in the 1.x series (1.4.29), you'd get a better error message:
npm ERR! Error: This version of npm doesn't support scoped packages (caused by reference to #types/lodash). Update to npm#2+.
Version 1.4.9 did not even know that scoped packages were a thing, so it cannot give a nice error message. It looks like it took the # symbol as signifying that the package name is an address and filled in the missing information with Github as the default host.
The upgrade command I typically use to upgrade npm is:
npm install -g npm
You can specify a specific version by replacing the npm argument with one that gives specific version number. npm#4, for instance, would install the latest npm in the 4.x series. If you don't specify a version number, you get the latest released version.

How can I add a .npmrc file?

I installed node on my Mac OS Sierra. I use Windows at my work so there I have a .npmrc file in the node folder but I don't seem to find that in mac.
The problem is I want to add a registry of the format
"scope=rohit-project#rohit-aquila:registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=some-token"
How do I add it so that I can install the dependencies and modules for my project by running npm install on MAC OS Sierra.
I created a .npmrc file simply and added the above code...and therefater running npm install I get the following error
rohitsrivastava$ npm install
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v7.7.3
npm ERR! npm v4.1.2
npm ERR! code E404
npm ERR! 404 Not found : #rohit-project/notes
npm ERR! 404
npm ERR! 404 '#rohit-project/notes' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of '#rohit-project/mega'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
There are a few different points here:
Where is the .npmrc file created.
How can you download private packages
Running npm config ls -l will show you all the implicit settings for npm, including what it thinks is the right place to put the .npmrc (the field userconfig), as this is environment/operating system dependant. But if you have never logged in (using npm login) it will be empty. Simply log in to create it.
To just output the path prop, issue npm config get userconfig.
Another thing is #2 - downloading private packages. You can actually do that by putting a .npmrc file in the NPM package's root. It will then be used by NPM when authenticating. It also supports variable interpolation from your shell so you could do stuff like this:
; Get the auth token to use for fetching private packages from our private scope
; see http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules
; and also https://docs.npmjs.com/files/npmrc
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
Pointers
http://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules
https://docs.npmjs.com/files/npmrc
In MacOS Catalina 10.15.5 the .npmrc file path can be found at
/Users/<user-name>/.npmrc
Open in it in (for first time users, create a new file) any editor and copy-paste your token. Save it.
You are ready to go.
Note:
As mentioned by #oligofren, the command npm config ls -l will npm configurations. You will get the .npmrc file from config parameter userconfig
This issue is because of you having some local or private packages.
For accessing those packages you have to create .npmrc file for this issue. Just refer the following link for your solution. https://nodesource.com/blog/configuring-your-npmrc-for-an-optimal-node-js-environment
In my case, updating my npm version helped me. So just to be sure, make sure your npm is up to date.
npm install -g npm#latest
Assuming you are using VSTS run vsts-npm-auth -config .npmrc to generate new .npmrc file with the auth token

Resources