Windows-build-tools: run as administrator successfully installs to the wrong user

Created on 4 Apr 2017  路  3Comments  路  Source: felixrieseberg/windows-build-tools

Environment

Windows 10: Version 1607 (OS Build 14393.953)
node: v4.7.3
npm: 4.3.0
node-gyp: v3.6.0

Repro steps

  1. run cmd.exe as administrator (admin) while logged in as non-administrator account (me).
  2. install windows-build-tools successfully. Tools are installed here:
C:\Users\admin\AppData\Roaming\npm\node_modules\windows-build-tools
  1. attempt to use windows-build-tools from non-administrator account fails.
F:\tests\kerberos>npm install

> [email protected] install F:\tests\kerberos
> (node-gyp rebuild) || (exit 0)


F:\tests\kerberos>if not defined npm_config_node_gyp (node "C:\Users\Bruce\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe". To fix this, 1) install the .NET Framew
ork 2.0 SDK, 2) install Microsoft Visual Studio 2005 or 3) add the location of the component to the system path if it i
s installed elsewhere.  [F:\tests\kerberos\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\Bruce\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:12)
gyp ERR! System Windows_NT 10.0.14393
gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Users\\Bruce\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd F:\tests\kerberos
gyp ERR! node -v v4.7.3
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok

Note 1: node-gyp installed in 2 places

C:\Users\admin\AppData\Roaming\npm
C:\Users\me\AppData\Roaming\npm

Note 2: I tried logging out and logging back in to make sure my cmd windows were getting all the proper settings.

Workaround [IGNORE see Workaround in my next comment]

prepend PATH environment variable with admin tools path:

set PATH=C:\Users\admin\AppData\Roaming\npm;%PATH%

Then it has no trouble building Kerberos

Comments

Does installing windows-build-tools take into account this scenario? Or is it expecting the user to be an admin?

Running cmd.exe as administrator sets the USERPROFILE to the admin user account C:\Users\admin. This surprised me. I had expected admin credentials but still my account.

I examined control panel->System->Advanced system settings->Environment Variables and I could not find C:\Users\admin\AppData\Roaming\npm anywhere. Nor could I find C:\Users\me\AppData\Roaming\npm

Most helpful comment

I kept digging around and found that the install placed the .windows-build-tools folder under the %USERPROFILE% directory. So this implied that for an install to work there had to be a usable %USERPROFILE%.

Better Workaround

The best workaround I found was:

  1. From your non-admin account (e.g. ). run as administrator cmd.exe.
  2. Set the following environment variables in the new command shell:
set APPDATA=C:\Users\<Me>\AppData\Roaming
npm config set prefix C:\Users\<Me>\AppData\Roaming\npm
set USERNAME=<Me>
set USERPROFILE=C:\Users\<Me>

substitute your non-admin account name for <Me>. See npm config set prefix description here.

  1. npm install -g --production windows-build-tools
  2. All installs well and node-gyp seems to work properly. As a test try the following:
git clone https://github.com/christkv/kerberos.git
cd kerberos
npm install

If this runs without errors then you have node-gyp working.

  1. Immediately close the cmd.exe window and make sure you do not install anything else with this config :-).

Now I have windows-build-tools installed to my non-admin account. And node-gyp behaves.

Comments

  • I tried installing to the global windows directory C:\Program Files (x86)\nodejs but it would still install bits to %USERPROFILE% and node-gyp could not find them. So I could not really install to the global shared windows directory.

  • The workaround to add C:\Users\Admin\AppData\Roaming\npm to my user path works. But this introduces a lot of problems and I only really want this to be true when using node-gyp. This Better Workaround is much better because I only need the funky config for installing windows-build-tools all other installs/builds work fine in a normal config.

PS: I cannot believe how much time I spend on node-gyp issues running in Windows. This package is a godsend to simplify the process, now I have it running in my non-admin account and I am happy.

All 3 comments

I kept digging around and found that the install placed the .windows-build-tools folder under the %USERPROFILE% directory. So this implied that for an install to work there had to be a usable %USERPROFILE%.

Better Workaround

The best workaround I found was:

  1. From your non-admin account (e.g. ). run as administrator cmd.exe.
  2. Set the following environment variables in the new command shell:
set APPDATA=C:\Users\<Me>\AppData\Roaming
npm config set prefix C:\Users\<Me>\AppData\Roaming\npm
set USERNAME=<Me>
set USERPROFILE=C:\Users\<Me>

substitute your non-admin account name for <Me>. See npm config set prefix description here.

  1. npm install -g --production windows-build-tools
  2. All installs well and node-gyp seems to work properly. As a test try the following:
git clone https://github.com/christkv/kerberos.git
cd kerberos
npm install

If this runs without errors then you have node-gyp working.

  1. Immediately close the cmd.exe window and make sure you do not install anything else with this config :-).

Now I have windows-build-tools installed to my non-admin account. And node-gyp behaves.

Comments

  • I tried installing to the global windows directory C:\Program Files (x86)\nodejs but it would still install bits to %USERPROFILE% and node-gyp could not find them. So I could not really install to the global shared windows directory.

  • The workaround to add C:\Users\Admin\AppData\Roaming\npm to my user path works. But this introduces a lot of problems and I only really want this to be true when using node-gyp. This Better Workaround is much better because I only need the funky config for installing windows-build-tools all other installs/builds work fine in a normal config.

PS: I cannot believe how much time I spend on node-gyp issues running in Windows. This package is a godsend to simplify the process, now I have it running in my non-admin account and I am happy.

This is excellent advice, thank you so much. I've added it to the README!

The solution by brucejo75 didn't work for me!!! any suggestions please..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zcwgd163 picture zcwgd163  路  3Comments

mohdsameer7408 picture mohdsameer7408  路  7Comments

d3x0r picture d3x0r  路  6Comments

dy picture dy  路  6Comments

keithnbrown picture keithnbrown  路  12Comments