VSCode git "npm command not found" [duplicate] - visual-studio-code

I've setup a node project with husky but when my collegue tries to run npm install on his Mac he gets the following error :
noa-be#1.0.0 prepare
husky install
sh: husky: command not found
npm ERR! code 127
npm ERR! path /Users/X/Desktop/Workspace/project
npm ERR! command failed
npm ERR! command sh -c husky install
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/X/.npm/_logs/2021-04-12T13_07_25_842Z-debug.log
These are the relevant package.json parts:
{
"scripts": {
"prepare": "husky install"
},
"devDependencies": {
"husky": "^5.2.0",
}
}
I thought this would be enough for husky to be installed when running npm install, but it's not. What am I missing?

If you are using nvm, you might want to create a file called .huskyrc in your home directory and add the following lines of code to it:
~/.huskyrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

I was struggling with the same exact problem for hours. Finally, I could install dependencies and start working on my project by doing this:
Temporarily remove the "prepare": "husky install" script from the package.json file.
Run npm i (npm install). Dependencies installed successfuly.
Add again the "prepare" script that you removed in step 1.
Run again npm i to install the husky git hooks, so husky can do its job from now on.

This error is also thrown by npm ci if the NODE_ENV is set to "production" pre-install

I've been able to solve the problem by upgrading to latest Husky version (7.0.1, from 5.2.0).
Git was also helpful, and told me that the files weren't executables. (Git V 2.24.1)
So I give them executable rights :
chmod +x PATH_TO_HUSKY_FILE
You'll need to execute this command for every hooks

I believe it could be version specific issue. Install version 6, npm i husky#6.0.0 --save-dev, and it should work as the husky doc says.
Apparently, when I did npm i husky --save-dev, it was installing "husky": "^0.8.1" for me for some strange reason, giving me the exact same error: sh: husky: command not found.
Method 1:
Update manually, in your package.json:
{
"scripts": {
"prepare": "husky install",
"create-hook": "husky add .husky/pre-commit \"npm test\"",
}
}
Then, run npm run prepare && npm run create-hook.
It should create .husky directory with .pre-commit file in it.
Method 2:
npx husky install
npm set-script prepare "husky install"
npx husky add .husky/pre-commit "npm test"

It worked in my terminal but not in VSCode version control. So had to force quite the vscode app and restarting it worked.

Faced this issue in Github Desktop.
solved it by quit Github Desktop and re-open it.

I was able to fix this by providing an explicit location for husky
"scripts": {
"prepare": "node_modules/.bin/husky-run install"
},

Using Lerna
When I upgraded husky from version 4 to 8 there was information todo first pre commit manually. For this purpose pre-commit bash script was generated in .husky directory.
What I had todo was simply run the command included in this file:
lerna run precommit --concurrency 2 --stream

Related

ionic can't serve project (exit code 13)

I'm a beginner of ionic. I download repo and couldn't start it.(I try npm install) I getting an exit code 13. How can I solve this problem.
try command
npm install #ionic/app-scripts#latest --save-dev
and update python to the latest version 3.9.4
Add a new script inside your package.json as lets say
"start": "ionic serve --port=8080"
Then run npm run start from the command line/terminal
what do you get?

Use vscode insider extension API

I am writing a VSCode extension but I need to use the latest extension API. How do I tell my package.json to use the insider version of the vscode API in my extension? I've tried:
"devDependencies": {
[...],
"vscode": "^1.22.0-insider"
},
but I get:
$ npm install
npm ERR! code ETARGET
npm ERR! notarget No matching version found for vscode#^1.22.0-insider
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
In your package.json, set:
"engines": {
"vscode:" "*"
}
Then run the npm postinstall script again (or just run npm install to retrigger it)
* pulls in the latest vscode.d.ts from VS Code's actively developed branch on github. Make sure to change engines to a real VS Code version such as "^1.28.0" before shipping your extension

Install specific branch from github using Npm

I would like to install bootstrap-loader from github in my project using npm
Currently they are maintaining two version of this project which are comaptible with webpack version 1 and 2.
I would like to install version 1. What npm command I should use to install this?
I tried using below one but it is not working.
npm install git://github.com/shakacode/bootstrap-loader.git[#v1] --Save
There are extra square brackets in the command you tried.
To install the latest version from the brach-name branch, you can use:
npm install "https://github.com/shakacode/bootstrap-loader.git#branch-name" --save
npm: npm install username/repo#branchName --save
yarn: yarn add username/repo#branchName
e.g. npm i betimer/rtc-attach#master --save (my username is betimer)
// this will appear in your package.json:
"rtc-attach": "github:betimer/rtc-attach#master"
One thing I also want to mention: it's not a good idea to check in the package.json for the build server auto pull the change. Instead, put the npm i (first command) into the build command, and let server just install and replace the package.
One more note, if the package.json private is set to true, may impact sometimes.
you can give git pattern as version, yarn and npm are clever enough to resolve from a git repo.
yarn add any-package#user-name/repo-name#branch-name
or for npm
npm install --save any-package#user-name/repo-name#branch-name
Another approach would be to add the following line to package.json dependencies:
"package-name": "user/repo#branch"
For example:
"dependencies": {
... other dependencies ...
"react-native": "facebook/react-native#master"
}
And then do npm install or yarn install
I'm using SSH to authenticate my GitHub account and have a couple dependencies in my project installed as follows:
"dependencies": {
"<dependency name>": "git+ssh://git#github.com/<github username>/<repository name>.git#<release version | branch>"
}
Had to put the url in quotes for it work
npm install "https://github.com/shakacode/bootstrap-loader.git#v1" --save
Tried suggested answers, but got it working only with this prefix approach:
npm i github:user/repo.git#version --save -D
Only solution working for me:
$ npm i https://github.com/{USER}/{REPO}/tarball/{BRANCH} --save
as explained here.
Both below versions work for me as of beginning of 2023:
npm i "github:shakacode#bootstrap-loader"
npm i "https://github.com/shakacode/tree/bootstrap-loader/"
The Doc of the npm defines that only tag/version can be specified after repo_url.
Here is the Doc: https://docs.npmjs.com/cli/install

Mean is not recognized as a internal command

npm install -g mean-cli works. but mean init says mean is not recognized as a internal command. How do I fix this?
I installed mean-cli from git, worked like a charm.
Open CMD
Run this: npm install -g git://github.com/djskinner/mean-cli.git
Hope this works for you too
It is possibly a NPM cache issue. Try running the following:
Update NPM
npm update -g npm
Then clear your NPM cache
npm cache clean
Once both commands have successfully ran, continue with the init
mean init <yourAppName>
For more reference material be sure to check out the docs at learn.mean.io.

How to install an npm package from GitHub directly

Trying to install modules from GitHub results in this error:
ENOENT error on package.json.
Easily reproduced using express:
npm install https://github.com/visionmedia/express throws error.
npm install express works.
Why can't I install from GitHub?
Here is the console output:
npm http GET https://github.com/visionmedia/express.git
npm http 200 https://github.com/visionmedia/express.git
npm ERR! not a package /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/tmp.tgz
npm ERR! Error: ENOENT, open '/home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 3.8.0-23-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/visionmedia/express.git"
npm ERR! cwd /home/guym/dev_env/projects_GIT/proj/somename
npm ERR! node -v v0.10.10
npm ERR! npm -v 1.2.25
npm ERR! path /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/guym/dev_env/projects_GIT/proj/somename/npm-debug.log
npm ERR! not ok code 0
Because https://github.com/visionmedia/express is the URL of a web page and not an npm module. Use this flavor: git+{url}.git
git+https://github.com/visionmedia/express.git
or this flavor if you need SSH:
git+ssh://git#github.com/visionmedia/express.git
or if you need to install a GitHub Enterprise repository:
git+https://<github enterprise url>/<org>/<repo>.git#<branch>
To install from GitHub, you can also do
npm install visionmedia/express
Or
npm install visionmedia/express#branch
There is also support for installing directly from a Gist, Bitbucket, GitLab, and a number of other specialized formats. Look at the npm install documentation for them all.
If Git is not installed, we can try:
npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master
As of September 2016, installing from vanilla HTTPS GitHub URLs now works:
npm install https://github.com/fergiemcdowall/search-index.git
You can't do this for all modules because you are reading from a source control system, which may well contain invalid/uncompiled/buggy code. So to be clear (although it should go without saying): given that the code in the repository is in an npm-usable state, you can now quite happily install directly from GitHub.
In October 2019, we are now living through "peak TypeScript/React/Babel", and therefore JavaScript compilation has become quite common. If you need to take compilation into account, look into prepare. That said, NPM modules do not need to be compiled, and it is wise to assume that compilation is not the default, especially for older node modules (and possibly also for very new, bleeding-edge "ESNext"-y ones).
The methods are covered pretty well now in npm's install documentation as well as the numerous other answers here.
npm install git+ssh://git#github.com:<githubname>/<githubrepo.git[#<commit-ish>]
npm install git+ssh://git#github.com:<githubname>/<githubrepo.git>[#semver:^x.x]
npm install git+https://git#github.com/<githubname>/<githubrepo.git>
npm install git://github.com/<githubname>/<githubrepo.git>
npm install github:<githubname>/<githubrepo>[#<commit-ish>]
However, something notable that has changed recently is npm adding the prepare script to replace the prepublish script. This fixes a long-standing problem where modules installed via Git did not run the prepublish script and thus did not complete the build steps that occur when a module is published to the npm registry. See Run prepublish for Git URL packages #3055.
Of course, the module authors will need to update their package.json file to use the new prepare directive for this to start working.
There's also npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH} to use a different branch.
The current top answer by Peter Lyons is not relevant with recent NPM versions. For example, using the same command that was criticized in this answer is now fine.
npm install https://github.com/visionmedia/express
If you have continued problems it might be a problem with whatever package you were using.
The general form of the syntax is
<protocol>://[<user>[:<password>]#]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
which means for your case it will be
npm install git+ssh://git#github.com/visionmedia/express.git
From npmjs docs:
npm install :
Installs the package from the hosted git provider, cloning it with
git. For a full git remote url, only that URL will be attempted.
<protocol>://[<user>[:<password>]#]<hostname>[:<port>][:][/]<path>[#<commit-ish>
| #semver:] is one of git, git+ssh, git+http,
git+https, or git+file.
If # is provided, it will be used to clone exactly that
commit. If the commit-ish has the format #semver:,
can be any valid semver range or exact version, and npm will look for
any tags or refs matching that range in the remote repository, much as
it would for a registry dependency. If neither # or
semver: is specified, then master is used.
If the repository makes use of submodules, those submodules will be
cloned as well.
If the package being installed contains a prepare script, its
dependencies and devDependencies will be installed, and the prepare
script will be run, before the package is packaged and installed.
The following git environment variables are recognized by npm and will
be added to the environment when running git:
GIT_ASKPASS
GIT_EXEC_PATH
GIT_PROXY_COMMAND
GIT_SSH
GIT_SSH_COMMAND
GIT_SSL_CAINFO GIT_SSL_NO_VERIFY
See the git man page for details.
Examples:
npm install git+ssh://git#github.com:npm/npm.git#v1.0.27
npm install git+ssh://git#github.com:npm/npm#semver:^5.0
npm install git+https://isaacs#github.com/npm/npm.git
npm install git://github.com/npm/npm.git#v1.0.27
GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git#github.com:npm/npm.git npm install
You can do:
npm install git://github.com/foo/bar.git
Or in package.json:
"dependencies": {
"bar": "git://github.com/foo/bar.git"
}
This works for me and it is less typing.
npm i github:<UserName>/<RepoName>
package.json
{
"dependencies": {
"name": "github:<UserName>/<RepoName>"
}
}
Install it directly:
npm install visionmedia/express
Alternatively, you can add "express": "github:visionmedia/express" to the "dependencies" section of package.json file, then run:
npm install
You could also do
npm i alex-cory/fasthacks
or
npm i github:alex-cory/fasthacks
Basically:
npm i user_or_org/repo_name
Sometimes I need to install from a specific branch or commit.
To make things simple I just use https://gitpkg.vercel.app/
You can directly install a GitHub repository by the npm install command, like this:
npm install https://github.com/futurechallenger/npm_git_install.git --save
NOTE: In the repository which will be installed by npm command:
maybe you have to have a dist folder in you repository, according to Dan Dascalescu's comment.
You definitely have to have a package.json in your repository! Which I forget add.
Simple:
npm install *GithubUrl*.git --save
Example:
npm install https://github.com/visionmedia/express.git --save
I tried npm install git+https://github.com/visionmedia/express but that took way too long and I wasn't sure that would work.
What did work for me was - yarn add git+https://github.com/visionmedia/express.
Below piece of code worked for me to install from github repository:
npm install git+ssh://<your_repository_ssh_clone_link>#<branch_name_if_any>
You can get ssh clone link as below:
So for above screenshot repository, you may need to import as below,
npm install git+ssh://git#github.com:Siddhu2/calculator-chatbot.git#master
where master is my branch and it is optional since I have only one branch.
If you get something like this:
npm ERR! enoent undefined ls-remote -h -t https://github.com/some_repo/repo.git
Make sure you update to the latest npm and that you have permissions as well.
The only command that worked for me was npm i MY_PACKAGE_NAME:MY_REPOSITORY#BRANCH_NAME
No need to do much; this helped me:
Yarn add <git_name>:<github_name>/<Repository_name>.git
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git
And if you want to add some specific commit or branch name then add #.
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git#master
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git#c978U57
Yarn 2 requires the package name along with the Github repository. Read the documentation of Yarn's CLI.
Example: yarn add <package_name>git#github.com:<owner_name>/<package_name>.git
Try this command:
npm install github:[Organisation]/[Repository]#[master/BranchName] -g
This command worked for me:
npm install github:BlessCSS/bless#3.x -g