npm install -g karma error MSB4019: 未找到导入的项目“C:\Microsoft.Cpp.Default.props”

Posted

技术标签:

【中文标题】npm install -g karma error MSB4019: 未找到导入的项目“C:\\Microsoft.Cpp.Default.props”【英文标题】:npm install -g karma error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not foundnpm install -g karma error MSB4019: 未找到导入的项目“C:\Microsoft.Cpp.Default.props” 【发布时间】:2013-09-17 11:15:46 【问题描述】:

我一直在研究 AngularJS 并遵循其安装步骤,但运行步骤 #1 时出现错误:

npm install -g karma

这是完整的输出:

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)

听起来正在运行的 MSBuild 版本(我相信是 12.0)没有正确解析 vcxproj 文件中的 $(VCTargetsPath) 变量。

【问题讨论】:

【参考方案1】:

在 Windows 上,我发现解决此问题的最简单方法是按照 README for node-gyd 的建议安装 windows-build-tools

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

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

这样我就不必自己安装python或其他dist包了。

【讨论】:

非常感谢!我不得不以管理员权限执行它,之后安装Sharp终于奏效了。【参考方案2】:

确保您拥有运行node-gyp所需的所有软件:

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

您可以通过环境变量配置 gyp 使用的 Visual Studio 版本,这样您就可以避免为将来的安装设置 --msvs_version=2012 属性。

例子:

为 Visual Studio 2012 设置 GYP_MSVS_VERSION=2012 设置GYP_MSVS_VERSION=2013e('e'代表'express edition')

完整列表见 - https://github.com/joyent/node/blob/v0.10.29/tools/gyp/pylib/gyp/MSVSVersion.py#L209-294

这对于 NodeJS 的 Windows 用户来说仍然很痛苦,因为它假定您安装了 Python 和 Visual Studio 的副本,但许多最终用户永远不会拥有这个。因此,我正在游说 Joyent 鼓励他们将 Web 套接字作为 CORE 节点的一部分,并将 GNU gcc 编译器作为 NodeJS 安装的一部分,这样我们就可以永久解决这个问题。

欢迎在以下位置添加您的投票:

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

【讨论】:

这种痛苦大多已成为过去。在 Microsoft 的帮助下,NodeJS 团队已经解决了这个问题。【参考方案3】:

对于那些使用 Windows SDK 安装 VS 并尝试 Besrl 的解决方案后仍然遇到错误的人,特别是 node-gyp 失败

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

尝试从 MSVS 命令提示符运行 npm install 命令。

Start menu > Microsoft Visual Studio 201X > Visual Studio Tools > Open Visual Studio 201X Tools Command Prompt 找到它,或者从命令提示符运行&lt;Program Files&gt;\&lt;VS dir&gt;\Common7\Tools\VsDevCmd.bat

以上内容在 VS2012 中对我有用,this Github comment 帮助我找到了这一点。

【讨论】:

请注意:“在开始菜单中查找 > Microsoft Visual Studio 201X...”可能是“Microsoft Visual Studio XX.X”【参考方案4】:

在安装 VS Express 2013 for web 和 VS Express 2012 for Windows 后,我在其他模块上遇到了同样的问题。 解决方案是安装 VS 2013 for Windows 并使用开关

npm install --msvs_version=2013

【讨论】:

太棒了,效果很好!要明确使用 2013 安装 AngularJS 的 foll 命令是 npm install -g karma --msvs_version=2013 非常感谢!我在安装strongloop时遇到了同样的问题。随着开关它开始工作。 重要的是要知道,您至少需要 VS Express for Desktop 才能使其工作。我只安装了 VS Express for Web,rhis 似乎还不够。 这对我有用,但分别适用于 2017 版。我想补充一点,使用 npm config 设置这个值对我不起作用,我必须在 install 命令的行中调用它。【参考方案5】:

如果您根本没有安装 Visual Studio,那么您肯定需要https://***.com/a/18779641/530967 的答案。

基本上,您必须安装一些版本的 Visual Studio 2010(Express 版本是免费的),然后是 Windows SDK,然后是 VS SP1,然后是 VC++ 编译器更新,所有这些都按此顺序进行。之后这个问题应该会消失(就像对我一样。)

【讨论】:

谢谢,我没有意识到订单很重要。我还安装了 2013,这可能会造成干扰。

以上是关于npm install -g karma error MSB4019: 未找到导入的项目“C:\Microsoft.Cpp.Default.props”的主要内容,如果未能解决你的问题,请参考以下文章

Centos7 install python-rrdtoll-1.47 erro

yum install报错“Transaction check erro"

npm全局安装的时候报错Error: EACCES: permission denied, open 。。。。

karma与webpack结合

How to Fix "Linux Failure to Download extra data files for ttf-mscorefonts-installer" erro

Karma 无法匹配任何 js 文件