Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI Git Hook fails when env defined in .npmrc #131

Closed
chrisblossom opened this issue May 22, 2017 · 17 comments
Closed

GUI Git Hook fails when env defined in .npmrc #131

chrisblossom opened this issue May 22, 2017 · 17 comments

Comments

@chrisblossom
Copy link

my .npmrc:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}
save-exact = true
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree commit -q -F /var/folders/hm/n_tq5p6j7j313n28pjzvk63c0000gn/T/SourceTreeTemp.SaYrXv -a 
Error: Failed to replace env in config: ${NPM_TOKEN}
    at /Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:418:13
    at RegExp.[Symbol.replace] (native)
    at RegExp.[Symbol.replace] (native)
    at String.replace (native)
    at envReplace (/Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:414:12)
    at parseField (/Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:392:7)
    at /Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:335:17
    at Array.forEach (native)
    at Conf.add (/Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:334:23)
    at ConfigChain.addString (/Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/node_modules/config-chain/index.js:244:8)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v6.10.3 --silent` to unset it.
Found '/Users/chris/github/app/.nvmrc' with version <6.10.3>
Error: Failed to replace env in config: ${NPM_TOKEN}
    at /Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:418:13
    at RegExp.[Symbol.replace] (native)
    at RegExp.[Symbol.replace] (native)
    at String.replace (native)
    at envReplace (/Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:414:12)
    at parseField (/Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:392:7)
    at /Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:335:17
    at Array.forEach (native)
    at Conf.add (/Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/config/core.js:334:23)
    at ConfigChain.addString (/Users/chris/.nvm/versions/node/v6.10.3/lib/node_modules/npm/node_modules/config-chain/index.js:244:8)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v6.10.3` to unset it.
> husky - Can't find npm in PATH. Skipping precommit script in package.json
Completed successfully
@MikelArnaiz
Copy link

Same here.

In Sourcetree and Fork the precommit is not run allowing you to commit.

In my .npmrc I have:

//rll.jfrog.io/rll/api/npm/my-npm/:_authToken=${NPM_TOKEN}
engine-strict=true

Modifying ./.git/hooks/pre-commit after the message husky > can't find npm in PATH, skipping precommit script in package.json with an exit 1 instead exit 0 will abort the commit and give you the error message:

Pre-commit hook 'pre-commit' has failed:

Error: Failed to replace env in config: ${NPM_TOKEN}
    at /Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/config/core.js:415:13
    at String.replace (<anonymous>)
    at envReplace (/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/config/core.js:411:12)
    at parseField (/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/config/core.js:389:7)
    at /Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/config/core.js:330:24
    at Array.forEach (<anonymous>)
    at Conf.add (/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/config/core.js:328:23)
    at ConfigChain.addString (/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/node_modules/config-chain/index.js:244:8)
    at Conf.<anonymous> (/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/config/core.js:316:10)
    at /Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/npm.js:61
      throw new Error('npm.load() required')
      ^

Error: npm.load() required
    at Object.get (/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/npm.js:61:13)
    at process.errorHandler (/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/lib/node_modules/npm/lib/utils/error-handler.js:205:18)
    at process.emit (events.js:182:13)
    at process._fatalException (internal/bootstrap/node.js:448:27)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v10.4.1 --silent` to unset it.
husky > can't find npm in PATH, skipping precommit script in package.json

I see that indeed that npm is not in the PATH, which is:

echo $PATH
/Users/MY-USERNAME/.nvm/versions/node/v10.4.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

but husky sees this PATH

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local

As you can see I'm using nvm

@manuel-reil
Copy link

Have you guys found a solution to this?

@lukeselbeck
Copy link

I'm still getting this, why was this closed? What's the solution?

@lukeselbeck
Copy link

Figured out my problem. For any future peoples: I was commiting/pushing with vscode and that was giving me the above error. When I commit/push with the terminal, it works fine!

@Ethaan
Copy link

Ethaan commented Jul 17, 2020

@lukeselbeck i'm commiting/pushing using git kraken and visual studio, there should be a way to export variables for husky

@youssef-tharwat
Copy link

Why is this closed?

@malikalimoekhamedov
Copy link

Yes, why is this closed?

@sexta13
Copy link

sexta13 commented Mar 7, 2021

I'm facing same issue as well...

@paschalidi
Copy link

paschalidi commented Jun 7, 2021

Still having this issue when I am committing with gitkraken. Perhaps we could reopen, @chrisblossom what you think?

@chrisblossom
Copy link
Author

Still having this issue when I am committing with gitkraken. Perhaps we could reopen, @chrisblossom what you think?

Because this issue was created so long ago and I closed it without commenting why (my mistake, sorry!), I would recommend opening a new issue with a link to this issue in-case it is still relevant.

@paschalidi
Copy link

Will do thanks

@SalahAdDin
Copy link

I'm facing this problem again, with the last husky version.

@MacRayy
Copy link

MacRayy commented Aug 11, 2021

I'm having the same issue with GitKraken

@carpben
Copy link

carpben commented Jan 3, 2022

Facing the same issue with Sourcetree.

@YousefMMS
Copy link

Having the same issue with Sourcetree & vscode

@carpben
Copy link

carpben commented Feb 4, 2022

I published a solution on StackOverflow. Can you please try it out and let me know if it works for you too?
https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x/70959181#70959181

@michealroberts
Copy link

This should't be closed as the above fix does not work for me, using Github Desktop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests