Error while trying to install an npm module from git - node.js

I forked and module on Github, changed it for my needs and pushed back to git. Now I am trying to install this module with npm with
npm install git+http://github.com/username/modulename.git
But I get the following error:
npm ERR! Command failed: git submodule update -q --init --recursive
npm ERR! fatal: O:/Programs/Git/mingw64/libexec/git-core\git-submodule cannot be used without a working tree.
What can cause it and how to fix it?

Check if this is similar to this thread:
After a bit of debugging, I have determined that this actually works if I use the url "https://github.com/nfroidure/ttf2woff2#master" instead.
This is because it is doing a shallow clone, which doesn’t use --mirror, so isn’t a bare repository.
So in your case:
npm install "https://github.com/username/modulename.git#master"

Related

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

npm install no longer possible after deleting module directory

So I wanted to help out, and forked a Node-RED module to make some small contribution, but then got lost messing around with how to get Node-RED to run my fork (for testing) rather than the packaged version. Then I learned about npm's ability to install from a Github URL, which is nice, but it wouldn't work because I had already installed the module. Then I found I couldn't uninstall it either
npm uninstall original-module
npm ERR! path /home/nodered/.node-red/node_modules/original-module/package.json
npm ERR! code ELOOP
npm ERR! errno -40
npm ERR! syscall open
npm ERR! ELOOP: too many symbolic links encountered, open '/home/nodered/.node-red/node_modules/original-module/package.json'
so in frustration I deleted the module's directory, only to find myself unable to move forwards, or backwards. npm install https://github.com/me/forkedmodule fails with
npm ERR! code 128
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master https://github.com/me/forkedmodule.git /root/.npm/_cacache/tmp/git-clone-d31dc53b
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-d31dc53b': Permission denied
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-08-22T01_07_18_257Z-debug.log
and trying to install the original with npm install original-module fails with
npm ERR! code ENOLOCAL
npm ERR! Could not install from "node_modules/original-module" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-08-22T01_09_56_127Z-debug.log
As you've probably guessed, I'm pretty new to Node.js, Node-RED and npm, but I haven't been able to help myself, so have to ask for help! It seems nonsensical to me that npm appears to be looking for a local copy of the package.json file belonging to the package I'm trying to install?
Edit: I should add that the above commands were all run as root.
Ok, found a solution, not sure if it's the best one though!
In the "project" directory (/home/nodered/.nodered in my case) there's a package-lock.json file which lists the packages used by the project. In there I found an entry for the original-module which I removed, after which I was able to install the package "normally" with npm install original-module.
Then to solve the permission issue when installing from a GitHub URL, I found I needed to impersonate the "nodered" user with su - nodered (it's a password-less user in my case). As "nodered" npm install https://github.com/me/forkedmodule succeeded without any error. A little curious since I was trying to do this as root before, and got a permission error, but there you go. I also took the opportunity to chown -R the project's node_modules directory to nodered:nodered as I could see that was a bit of mess.
In future, I will try to remember to su - to my nodered user first, and navigating to the project root (again, /home/nodered/.node-red in my case) before running npm install anything. Hopefully that will avoid any further issues. Oh and a note to anyone else who just wants to contrib some quick changes to a module hosted on GitHub: to "pull" in changes you simply run npm install https://github.com/me/forkedmodule again - npm doesn't appear to provide any dedicated "update" method.
I had the same issue, in my case the solution was to delete the package-lock.json, delete node_modules, then reinstall npm modules.

Polymer CLI - npm error code 1

I get this error when trying to install polymer CLI. I keep on getting this whenever i try to install it.
sudo npm install --unsafe-perm -g polymer-cli
Password:
npm WARN deprecated bower#1.8.0: ..psst! While Bower is maintained, we
recommend Yarn and Webpack for *new* front-end projects! Yarn's
advantage is security and reliability, and Webpack's is support for
both CommonJS and AMD projects. Currently there's no migration path but
we hope you'll help us figure out one.
npm WARN deprecated #types/assert#0.0.29: See
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/12826
npm ERR! code 1
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master
git://github.com/polymerelements/test-fixture.git
/Users/litsonthomas/.npm/_cacache/tmp/git-clone-eddd277b
npm ERR! /Users/litsonthomas/.npm/_cacache/tmp/git-clone-eddd277b/.git:
Permission denied
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/litsonthomas/.npm/_logs/2017-06-22T17_39_34_600Z-
debug.log
I am new to polymer and I don't know where am getting wrong!
This seems to be a pertinent issue in this package (issues in the repository: #784 #800). You have to go to the npm site on Fixing npm Permissions and follow the steps there.
You may receive an EACCES error when you try to install a package globally. This indicates that you do not have permission to write to the directories that npm uses to store global packages and commands.
You can fix this problem using one of three options:
Change the permission to npm's default directory.
Change npm's default directory to another directory.
Install node with a package manager that takes care of this for you.
Whether you should follow one of the three options depends on each particular case. What I would recommend first is to try changing the npm default directory to some place with user read/write permissions. Then, you should start doing npm i -g without sudo.

npm install trying to install from random fork

I got a node project that work fine at work on mac, but on windows at home it give me a access right error when I try to do npm install.
in my package.json I have this
"dependencies": {
"async": "2.1.4"
}
and it give me this error
npm ERR! Command failed: git -c core.longpaths=true clone C:\Users\username\AppData\Roaming\npm-cache\_git-remotes\git-github-com-jstewmon-async-git-e757f9b4 C:\Users\username\.babun\cygwin\tmp\npm-17984-bd5d3a5c\git-cache-52562eee\c6a89a49b0d525c41545e8afd9a4fe844033cc52
npm ERR! Cloning into 'C:\Users\username\.babun\cygwin\tmp\npm-17984-bd5d3a5c\git-cache-52562eee\c6a89a49b0d525c41545e8afd9a4fe844033cc52'...
npm ERR! fatal: '/cygdrive/c/Users/username/AppData/Roaming/npm-cache/_git-remotes/git-github-com-jstewmon-async-git-e757f9b4/C:\Users\username\AppData\Roaming\npm-cache\_git-remotes\git-github-com-jstewmon-async-git-e757f9b4' does not appear to be a git repository
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
seem to be trying to install from a fork of async.. I don't get it.
git-github-com-jstewmon-async-git-e757f9b4
https://github.com/jstewmon/async
I tried npm clean cache with no success.
As mentioned in npm issue 7456
I can confirm that this command fails "does not appear to be a git repository" when using the current git bundled with Cygwin (2.4.5) 64 bit.
When I separately download and install the Windows git distribution (2.6.2.windows.1) (now 2017 2.12.0), and put the GIT_HOME in front of the CYGWIN_HOME in the PATH, the npm install (including the git clone) succeeds.
I installed with the mintty option so that git works properly with docker also.
If you don't want to install Git on Windows, you can instead follow:
"npm_on_cygwin"
It involved a patched git.js, which will properly managed Windows path, instead of blindly concatenate it as in /cygdrive/c/.../C:\Users\....
The OP Devilwarriors mentions in the comments the npm issue 12821, a similar problem of double Git installed:
babun's sandboxed git can't download git repos when used through npm.
To solve this, you can uninstall babun's git with pact remove git and use the Git for Windows that you already have installed.

Installing git through .ebextensions on Elastic Beanstalk

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

Resources