npm install -g karma error MSB4019: The imported p

2019-01-10 18:08发布

问题:

I've been looking into AngularJS and following its install steps, but I get an error running step #1:

npm install -g karma

Here is the full output:

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\Travis>node --version
v0.10.18

C:\Users\Travis>python --version
Python 2.7.3

C:\Users\Travis>npm install -g karma
npm http GET https://registry.npmjs.org/karma
npm http 304 https://registry.npmjs.org/karma
npm http GET https://registry.npmjs.org/di
npm http GET https://registry.npmjs.org/socket.io
npm http GET https://registry.npmjs.org/chokidar
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/http-proxy
npm http GET https://registry.npmjs.org/colors/0.6.0-1
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/useragent
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/log4js
npm http GET https://registry.npmjs.org/q
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/di
npm http 304 https://registry.npmjs.org/chokidar
npm http 304 https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/colors/0.6.0-1
npm http 304 https://registry.npmjs.org/http-proxy
npm http 304 https://registry.npmjs.org/rimraf
npm http 304 https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/useragent
npm http 304 https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/log4js
npm http 304 https://registry.npmjs.org/q
npm http 304 https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/connect
npm http 304 https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/socket.io-client/0.9.16
npm http GET https://registry.npmjs.org/policyfile/0.0.4
npm http GET https://registry.npmjs.org/base64id/0.1.0
npm http GET https://registry.npmjs.org/redis/0.7.3
npm http 304 https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/policyfile/0.0.4
npm http 304 https://registry.npmjs.org/base64id/0.1.0
npm http 304 https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/redis/0.7.3
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/socket.io-client/0.9.16
npm http GET https://registry.npmjs.org/pkginfo
npm http GET https://registry.npmjs.org/utile
npm http GET https://registry.npmjs.org/qs/0.6.5
npm http GET https://registry.npmjs.org/cookie-signature/1.0.1
npm http GET https://registry.npmjs.org/formidable/1.0.14
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/send/0.1.4
npm http GET https://registry.npmjs.org/bytes/0.2.0
npm http GET https://registry.npmjs.org/fresh/0.2.0
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http GET https://registry.npmjs.org/uid2/0.0.2
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http 304 https://registry.npmjs.org/pkginfo
npm http 304 https://registry.npmjs.org/utile
npm http 304 https://registry.npmjs.org/qs/0.6.5
npm http 304 https://registry.npmjs.org/cookie/0.1.0
npm http 304 https://registry.npmjs.org/cookie-signature/1.0.1
npm http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http 304 https://registry.npmjs.org/send/0.1.4
npm http 304 https://registry.npmjs.org/bytes/0.2.0
npm http 304 https://registry.npmjs.org/fresh/0.2.0
npm http 304 https://registry.npmjs.org/pause/0.0.1
npm http 304 https://registry.npmjs.org/formidable/1.0.14
npm http 304 https://registry.npmjs.org/uid2/0.0.2
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/i
npm http GET https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/deep-equal
npm http GET https://registry.npmjs.org/ncp
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/deep-equal
npm http 304 https://registry.npmjs.org/ncp
npm http 304 https://registry.npmjs.org/async
npm http GET https://registry.npmjs.org/dequeue/1.0.3
npm http GET https://registry.npmjs.org/async/0.1.15
npm http GET https://registry.npmjs.org/semver
npm http 304 https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/i
npm http GET https://registry.npmjs.org/readable-stream
npm http 304 https://registry.npmjs.org/dequeue/1.0.3
npm http 304 https://registry.npmjs.org/async/0.1.15
npm http 304 https://registry.npmjs.org/readable-stream
npm http 304 https://registry.npmjs.org/semver
npm http GET https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http GET https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http 304 https://registry.npmjs.org/uglify-js/1.2.5
npm http 304 https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/zeparser/0.0.5
npm http 304 https://registry.npmjs.org/zeparser/0.0.5
npm http GET https://registry.npmjs.org/tinycolor
npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/commander
npm http 304 https://registry.npmjs.org/tinycolor

> ws@0.4.30 install C:\Users\Travis\AppData\Roaming\npm\node_modules\karma\node_modules\socket.io\node_modules\socket.io
-client\node_modules\ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)


C:\Users\Travis\AppData\Roaming\npm\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_modules
\ws>node "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js"
rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Users\Travis\AppData\Roaming\npm\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_module
s\ws\build\bufferutil.vcxproj(18,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found
. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
C:\Users\Travis\AppData\Roaming\npm\node_modules\karma\node_modules\socket.io\node_modules\socket.io-client\node_module
s\ws\build\validation.vcxproj(18,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found
. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
C:\Users\Travis\AppData\Roaming\npm\karma -> C:\Users\Travis\AppData\Roaming\npm\node_modules\karma\bin\karma
karma@0.10.2 C:\Users\Travis\AppData\Roaming\npm\node_modules\karma
├── di@0.0.1
├── rimraf@2.1.4
├── colors@0.6.0-1
├── graceful-fs@1.2.3
├── mime@1.2.11
├── chokidar@0.6.3
├── q@0.9.7
├── coffee-script@1.6.3
├── minimatch@0.2.12 (sigmund@1.0.0, lru-cache@2.3.1)
├── glob@3.1.21 (inherits@1.0.0)
├── optimist@0.3.7 (wordwrap@0.0.2)
├── lodash@1.1.1
├── useragent@2.0.7 (lru-cache@2.2.4)
├── connect@2.8.8 (methods@0.0.1, uid2@0.0.2, cookie-signature@1.0.1, pause@0.0.1, fresh@0.2.0, bytes@0.2.0, qs@0.6.5, b
uffer-crc32@0.2.1, cookie@0.1.0, debug@0.7.2, formidable@1.0.14, send@0.1.4)
├── http-proxy@0.10.3 (pkginfo@0.2.3, utile@0.1.7)
├── log4js@0.6.8 (dequeue@1.0.3, semver@1.1.4, async@0.1.15, readable-stream@1.0.17)
└── socket.io@0.9.16 (base64id@0.1.0, policyfile@0.0.4, redis@0.7.3, socket.io-client@0.9.16)

It sounds like the version of MSBuild that is running (12.0, I believe) isn't correctly resolving the $(VCTargetsPath) variable in the vcxproj file.

回答1:

I had the same issue with other modules after installing VS Express 2013 for web alongside VS Express 2012 for Windows. The solution was to install VS 2013 for Windows and use the switch

npm install --msvs_version=2013


回答2:

For those that still run into errors after installing a VS with Windows SDK and trying Besrl's solution, in particular node-gyp failing with

Error MSB4019: The imported project "X:\Microsoft.Cpp.Default.props" was not found,

Try running the npm install commands from a MSVS command prompt.

Find it at Start menu > Microsoft Visual Studio 201X > Visual Studio Tools > Open Visual Studio 201X Tools Command Prompt or run the <Program Files>\<VS dir>\Common7\Tools\VsDevCmd.bat from a command prompt.

The above worked for me with VS2012, and this Github comment helped me find that.



回答3:

Make sure you have all the required software to run node-gyp:

  • https://github.com/TooTallNate/node-gyp

You can configure the version of Visual Studio used by gyp via an environment variable so you can avoid having to set the --msvs_version=2012 property for future installs.

Examples:

  • set GYP_MSVS_VERSION=2012 for Visual Studio 2012
  • set GYP_MSVS_VERSION=2013e (the 'e' stands for 'express edition')

For the full list see - https://github.com/joyent/node/blob/v0.10.29/tools/gyp/pylib/gyp/MSVSVersion.py#L209-294

This is still painful for Windows users of NodeJS as it assumes you have a copy of Python and Visual Studio installed but many end users will never have this. So I'm lobbying Joyent to encourage them to include web sockets as part of CORE node and also to ship a GNU gcc compiler as part of NodeJS install so we can permanently fix this problem.

Feel free to add your vote at:

  • https://github.com/joyent/node/issues/8005#issuecomment-50545326


回答4:

On windows the easiest way that i found to fix this is to install the windows-build-tools as recommended by the README for node-gyd

npm install --global --production windows-build-tools

https://github.com/nodejs/node-gyp

This way i didnt have to mess with installing python or other dist packages myself.



回答5:

If you don't have Visual Studio installed at all, then you definitely need the answer at https://stackoverflow.com/a/18779641/530967.

Basically you have to install some version of Visual Studio 2010 (Express version is free), then the Windows SDK, then VS SP1, then a VC++ compiler update, all in that order. After that this problem should disappear (as it did for me.)