解决npm安装一直报错的问题

本文介绍了如何解决npm执行时因缺少写入权限导致的错误。通过为Node.js安装目录添加写入权限,可以避免此类问题。步骤包括定位Node.js文件夹,修改权限设置,确保System用户具有完全控制权限,特别是开启子容器和对象的所有者权限。遵循这些步骤,可以确保npm能够正常执行安装操作,避免报错。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

添加写入权限

npm全篇报错的最大原因之一是因为它无法写入,因此需要为他开启nodjes所在文件夹开启写入权限。
1.首先,找到nodejs文件夹。我本人的放在F盘,
在这里插入图片描述
2. 然后右键属性,点击到安全的一栏,为nodejs文件夹开启写入权限。由于本人已经开启了写入权限,因此这里已经打上对钩。

解决选择写入权限被拒绝的问题

在这里插入图片描述

  1. 点击“高级”之后,观察拥有“完全控制”权限的用户,我这里是System;
    在这里插入图片描述
  2. 点击有护盾标志的“更改”处,进入到如下界面:
    在这里插入图片描述
  3. 点击高级,首先点击“立即查找”,然后在“搜索结果”中找到System,点击确定;
    在这里插入图片描述
  4. 然后返回到下图界面,点击确定
    在这里插入图片描述
  5. 确定之后,勾选“子容器和对象的所有者”
    在这里插入图片描述
  6. 点击确定,即可观察到写入权限已经开启。
    在这里插入图片描述
    至此,再使用npm执行安装目录,即无报错信息。
    在这里插入图片描述
npm ERR! code 1 npm ERR! git dep preparation failed npm ERR! command D:\Program Files\nodejs\node.exe D:\node\nodejs\node_global\node_modules\npm\bin\npm-cli.js install --force --cache=D:\Program Files\nodejs\node_cache --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run npm ERR! npm WARN using --force Recommended protections disabled. npm ERR! npm WARN deprecated osenv@0.1.5: This package is no longer supported. npm ERR! npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. npm ERR! npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs npm ERR! npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm ERR! npm WARN deprecated lodash.isequal@4.5.0: This package is deprecated. Use require('node:util').isDeepStrictEqual instead. npm ERR! npm WARN deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead npm ERR! npm WARN deprecated move-concurrently@1.0.1: This package is no longer supported. npm ERR! npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility npm ERR! npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated npm ERR! npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated figgy-pudding@3.5.2: This module is no longer supported. npm ERR! npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated npmlog@4.1.2: This package is no longer supported. npm ERR! npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained npm ERR! npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained npm ERR! npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated consolidate@0.15.1: Please upgrade to consolidate v1.0.0+ as it has been modernized with several long-awaited fixes implemented. Maintenance is supported by Forward Email at https://forwardemail.net ; follow/watch https://github.com/ladjs/consolidate for updates and release changelog npm ERR! npm WARN deprecated copy-concurrently@1.0.5: This package is no longer supported. npm ERR! npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm ERR! npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm ERR! npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported npm ERR! npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported npm ERR! npm WARN deprecated q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other. npm ERR! npm WARN deprecated npm ERR! npm WARN deprecated (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) npm ERR! npm WARN deprecated glob@7.1.7: Glob versions prior to v9 are no longer supported npm ERR! npm WARN deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead npm ERR! npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated npm ERR! npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm ERR! npm WARN deprecated are-we-there-yet@1.1.7: This package is no longer supported. npm ERR! npm WARN deprecated html-webpack-plugin@3.2.0: 3.x is no longer supported npm ERR! npm WARN deprecated fs-write-stream-atomic@1.0.10: This package is no longer supported. npm ERR! npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address' npm ERR! npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates. npm ERR! npm WARN deprecated @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information. npm ERR! npm WARN deprecated gauge@2.7.4: This package is no longer supported. npm ERR! npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm ERR! npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm ERR! npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm ERR! npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm ERR! npm WARN deprecated webpack-chain@6.5.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. npm ERR! npm WARN deprecated fstream@1.0.12: This package is no longer supported. npm ERR! npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained npm ERR! npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi' npm ERR! npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x. npm ERR! npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap. npm ERR! npm WARN deprecated iltorb@2.4.5: The zlib module provides APIs for brotli compression/decompression starting with Node.js v10.16.0, please use it over iltorb npm ERR! npm WARN deprecated vue@2.6.14: Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details. npm ERR! npm WARN deprecated node-sass@4.14.1: Node Sass is no longer supported. Please use `sass` or `sass-embedded` instead. npm ERR! npm WARN deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options. npm ERR! npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, fea ture detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js. npm ERR! npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, fea ture detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js. npm ERR! npm WARN cleanup Failed to remove some directories [ npm ERR! npm WARN cleanup [ npm ERR! npm WARN cleanup 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\mozjpeg', npm ERR! npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\mozjpeg'] { npm ERR! npm WARN cleanup errno: -4082, npm ERR! npm WARN cleanup code: 'EBUSY', npm ERR! npm WARN cleanup syscall: 'rmdir', npm ERR! npm WARN cleanup path: 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\mozjpeg' npm ERR! npm WARN cleanup } npm ERR! npm WARN cleanup ], npm ERR! npm WARN cleanup [ npm ERR! npm WARN cleanup 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\optipng-bin', npm ERR! npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\optipng-bin'] { npm ERR! npm WARN cleanup errno: -4082, npm ERR! npm WARN cleanup code: 'EBUSY', npm ERR! npm WARN cleanup syscall: 'rmdir', npm ERR! npm WARN cleanup path: 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\optipng-bin' npm ERR! npm WARN cleanup } npm ERR! npm WARN cleanup ], npm ERR! npm WARN cleanup [ npm ERR! npm WARN cleanup 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\cwebp-bin', npm ERR! npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\cwebp-bin'] { npm ERR! npm WARN cleanup errno: -4082, npm ERR! npm WARN cleanup code: 'EBUSY', npm ERR! npm WARN cleanup syscall: 'rmdir', npm ERR! npm WARN cleanup path: 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\cwebp-bin' npm ERR! npm WARN cleanup } npm ERR! npm WARN cleanup ], npm ERR! npm WARN cleanup [ npm ERR! npm WARN cleanup 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\gifsicle', npm ERR! npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\gifsicle'] { npm ERR! npm WARN cleanup errno: -4082, npm ERR! npm WARN cleanup code: 'EBUSY', npm ERR! npm WARN cleanup syscall: 'rmdir', npm ERR! npm WARN cleanup path: 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\gifsicle' npm ERR! npm WARN cleanup } npm ERR! npm WARN cleanup ], npm ERR! npm WARN cleanup [ npm ERR! npm WARN cleanup 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\pngquant-bin', npm ERR! npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\pngquant-bin'] { npm ERR! npm WARN cleanup errno: -4082, npm ERR! npm WARN cleanup code: 'EBUSY', npm ERR! npm WARN cleanup syscall: 'rmdir', npm ERR! npm WARN cleanup path: 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\pngquant-bin' npm ERR! npm WARN cleanup } npm ERR! npm WARN cleanup ], npm ERR! npm WARN cleanup [ npm ERR! npm WARN cleanup 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules', npm ERR! npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\cwebp-bin'] { npm ERR! npm WARN cleanup errno: -4082, npm ERR! npm WARN cleanup code: 'EBUSY', npm ERR! npm WARN cleanup syscall: 'rmdir', npm ERR! npm WARN cleanup path: 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\cwebp-bin' npm ERR! npm WARN cleanup } npm ERR! npm WARN cleanup ], npm ERR! npm WARN cleanup [ npm ERR! npm WARN cleanup 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\@babel\\polyfill', npm ERR! npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\@babel\polyfill'] { npm ERR! npm WARN cleanup errno: -4048, npm ERR! npm WARN cleanup code: 'EPERM', npm ERR! npm WARN cleanup syscall: 'rmdir', npm ERR! npm WARN cleanup path: 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\@babel\\polyfill' npm ERR! npm WARN cleanup } npm ERR! npm WARN cleanup ] npm ERR! npm WARN cleanup ] npm ERR! npm ERR! code 1 npm ERR! npm ERR! path D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass npm ERR! npm ERR! command failed npm ERR! npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js npm ERR! npm ERR! Building: D:\Program Files\nodejs\node.exe D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= npm ERR! npm ERR! �ڴ˽��������һ������һ����Ŀ����Ҫ���ò������ɣ������ӡ�/m�����ء� npm ERR! npm ERR! ��������ʱ��Ϊ 2025/5/27 15:48:02�� npm ERR! npm ERR! �ڵ� 1 �ϵ���Ŀ��D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\build\binding.sln��(Ĭ��Ŀ��)�� npm ERR! npm ERR! ValidateSolutionConfiguration: npm ERR! npm ERR! �������ɽ���������á�Release|x64���� npm ERR! npm ERR! MSBUILD : error MSB3428: δ�ܼ��� Visual C++ �����VCBuild.exe����Ҫ��������⣬1) ��װ .NET Framework 2.0 SDK��2) ��װ Microsoft Visual Studio 2005���� 3) ������������װ��������λ�ã��뽫��λ�����ӵ�ϵͳ·���С� [D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\build\binding.sln] npm ERR! npm ERR! �����������Ŀ��D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\build\binding.sln��(Ĭ��Ŀ��)�IJ��� - ʧ�ܡ� npm ERR! npm ERR! npm ERR! npm ERR! ����ʧ�ܡ� npm ERR! npm ERR! npm ERR! npm ERR! ��D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\build\binding.sln��(Ĭ��Ŀ��) (1) -> npm ERR! npm ERR! (_src_\libsass Ŀ��) -> npm ERR! npm ERR! MSBUILD : error MSB3428: δ�ܼ��� Visual C++ �����VCBuild.exe����Ҫ��������⣬1) ��װ .NET Framework 2.0 SDK��2) ��װ Microsoft Visual Studio 2005���� 3) ������������װ��������λ�ã��뽫��λ�����ӵ�ϵͳ·���С� [D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\build\binding.sln] npm ERR! npm ERR! npm ERR! npm ERR! 0 ������ npm ERR! npm ERR! 1 ������ npm ERR! npm ERR! npm ERR! npm ERR! ����ʱ�� 00:00:00.40 npm ERR! npm ERR! gyp info it worked if it ends with ok npm ERR! npm ERR! gyp verb cli [ npm ERR! npm ERR! gyp verb cli 'D:\\Program Files\\nodejs\\node.exe', npm ERR! npm ERR! gyp verb cli 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\node-gyp\\bin\\node-gyp.js', npm ERR! npm ERR! gyp verb cli 'rebuild', npm ERR! npm ERR! gyp verb cli '--verbose', npm ERR! npm ERR! gyp verb cli '--libsass_ext=', npm ERR! npm ERR! gyp verb cli '--libsass_cflags=', npm ERR! npm ERR! gyp verb cli '--libsass_ldflags=', npm ERR! npm ERR! gyp verb cli '--libsass_library=' npm ERR! npm ERR! gyp verb cli ] npm ERR! npm ERR! gyp info using node-gyp@3.8.0 npm ERR! npm ERR! gyp info using node@14.20.0 | win32 | x64 npm ERR! npm ERR! gyp verb command rebuild [] npm ERR! npm ERR! gyp verb command clean [] npm ERR! npm ERR! gyp verb clean removing "build" directory npm ERR! npm ERR! gyp verb command configure [] npm ERR! npm ERR! gyp verb check python checking for Python executable "python2" in the PATH npm ERR! npm ERR! gyp verb `which` failed Error: not found: python2 npm ERR! npm ERR! gyp verb `which` failed at getNotFoundError (D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\node_modules\which\which.js:13:12) npm ERR! npm ERR! gyp verb `which` failed at F (D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\node_modules\which\which.js:68:19) npm ERR! npm ERR! gyp verb `which` failed at E (D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\node_modules\which\which.js:80:29) npm ERR! npm ERR! gyp verb `which` failed at D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\node_modules\which\which.js:89:16 npm ERR! npm ERR! gyp verb `which` failed at D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\isexe\index.js:42:5 npm ERR! npm ERR! gyp verb `which` failed at D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\isexe\windows.js:36:5 npm ERR! npm ERR! gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:192:21) npm ERR! npm ERR! gyp verb `which` failed python2 Error: not found: python2 npm ERR! npm ERR! gyp verb `which` failed at getNotFoundError (D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\node_modules\which\which.js:13:12) npm ERR! npm ERR! gyp verb `which` failed at F (D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\node_modules\which\which.js:68:19) npm ERR! npm ERR! gyp verb `which` failed at E (D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\node_modules\which\which.js:80:29) npm ERR! npm ERR! gyp verb `which` failed at D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\node_modules\which\which.js:89:16 npm ERR! npm ERR! gyp verb `which` failed at D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\isexe\index.js:42:5 npm ERR! npm ERR! gyp verb `which` failed at D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\isexe\windows.js:36:5 npm ERR! npm ERR! gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:192:21) { npm ERR! npm ERR! gyp verb `which` failed code: 'ENOENT' npm ERR! npm ERR! gyp verb `which` failed } npm ERR! npm ERR! gyp verb check python checking for Python executable "python" in the PATH npm ERR! npm ERR! gyp verb `which` succeeded python D:\Python27\python.EXE npm ERR! npm ERR! gyp verb check python version `D:\Python27\python.EXE -c "import sys; print "2.7.0 npm ERR! npm ERR! gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j npm ERR! npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 14.20.0 npm ERR! npm ERR! gyp verb command install [ '14.20.0' ] npm ERR! npm ERR! gyp verb install input version string "14.20.0" npm ERR! npm ERR! gyp verb install installing version: 14.20.0 npm ERR! npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed npm ERR! npm ERR! gyp verb install version is already installed, need to check "installVersion" npm ERR! npm ERR! gyp verb got "installVersion" 9 npm ERR! npm ERR! gyp verb needs "installVersion" 9 npm ERR! npm ERR! gyp verb install version is good npm ERR! npm ERR! gyp verb get node dir target node version installed: 14.20.0 npm ERR! npm ERR! gyp verb build dir attempting to create "build" dir: D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\build npm ERR! npm ERR! gyp verb build dir "build" dir needed to be created? D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\build npm ERR! npm ERR! gyp verb Not using VS2017: Could not use PowerShell to find VS2017 npm ERR! npm ERR! gyp verb build/config.gypi creating config file npm ERR! npm ERR! gyp verb build/config.gypi writing out config file: D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\build\config.gypi npm ERR! npm ERR! gyp verb config.gypi checking for gypi file: D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\config.gypi npm ERR! npm ERR! gyp verb common.gypi checking for gypi file: D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass\common.gypi npm ERR! npm ERR! gyp verb gyp gyp format was not specified; forcing "msvs" npm ERR! npm ERR! gyp info spawn D:\Python27\python.EXE npm ERR! npm ERR! gyp info spawn args [ npm ERR! npm ERR! gyp info spawn args 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\node-gyp\\gyp\\gyp_main.py', npm ERR! npm ERR! gyp info spawn args 'binding.gyp', npm ERR! npm ERR! gyp info spawn args '-f', npm ERR! npm ERR! gyp info spawn args 'msvs', npm ERR! npm ERR! gyp info spawn args '-G', npm ERR! npm ERR! gyp info spawn args 'msvs_version=auto', npm ERR! npm ERR! gyp info spawn args '-I', npm ERR! npm ERR! gyp info spawn args 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\node-sass\\build\\config.gypi', npm ERR! npm ERR! gyp info spawn args '-I', npm ERR! npm ERR! gyp info spawn args 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\node-gyp\\addon.gypi', npm ERR! npm ERR! gyp info spawn args '-I', npm ERR! npm ERR! gyp info spawn args 'C:\\Users\\23969\\.node-gyp\\14.20.0\\include\\node\\common.gypi', npm ERR! npm ERR! gyp info spawn args '-Dlibrary=shared_library', npm ERR! npm ERR! gyp info spawn args '-Dvisibility=default', npm ERR! npm ERR! gyp info spawn args '-Dnode_root_dir=C:\\Users\\23969\\.node-gyp\\14.20.0', npm ERR! npm ERR! gyp info spawn args '-Dnode_gyp_dir=D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\node-gyp', npm ERR! npm ERR! gyp info spawn args '-Dnode_lib_file=C:\\Users\\23969\\.node-gyp\\14.20.0\\<(target_arch)\\node.lib', npm ERR! npm ERR! gyp info spawn args '-Dmodule_root_dir=D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\node-sass', npm ERR! npm ERR! gyp info spawn args '-Dnode_engine=v8', npm ERR! npm ERR! gyp info spawn args '--depth=.', npm ERR! npm ERR! gyp info spawn args '--no-parallel', npm ERR! npm ERR! gyp info spawn args '--generator-output', npm ERR! npm ERR! gyp info spawn args 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\node-sass\\build', npm ERR! npm ERR! gyp info spawn args '-Goutput_dir=.' npm ERR! npm ERR! gyp info spawn args ] npm ERR! npm ERR! Warning: unrecognized setting VCCLCompilerTool/MultiProcessorCompilation npm ERR! npm ERR! Warning: unrecognized setting VCCLCompilerTool/MultiProcessorCompilation npm ERR! npm ERR! Warning: unrecognized setting VCCLCompilerTool/MultiProcessorCompilation npm ERR! npm ERR! Warning: unrecognized setting VCCLCompilerTool/MultiProcessorCompilation npm ERR! npm ERR! gyp verb command build [] npm ERR! npm ERR! gyp verb build type Release npm ERR! npm ERR! gyp verb architecture x64 npm ERR! npm ERR! gyp verb node dev dir C:\Users\23969\.node-gyp\14.20.0 npm ERR! npm ERR! gyp verb found first Solution file build/binding.sln npm ERR! npm ERR! gyp verb could not find "msbuild.exe" in PATH - finding location in registry npm ERR! npm ERR! gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe npm ERR! npm ERR! gyp info spawn args [ npm ERR! npm ERR! gyp info spawn args 'build/binding.sln', npm ERR! npm ERR! gyp info spawn args '/nologo', npm ERR! npm ERR! gyp info spawn args '/p:Configuration=Release;Platform=x64' npm ERR! npm ERR! gyp info spawn args ] npm ERR! npm ERR! gyp ERR! build error npm ERR! npm ERR! gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1 npm ERR! npm ERR! gyp ERR! stack at ChildProcess.onExit (D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-gyp\lib\build.js:262:23) npm ERR! npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:400:28) npm ERR! npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:285:12) npm ERR! npm ERR! gyp ERR! System Windows_NT 10.0.26100 npm ERR! npm ERR! gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\git-cloneuwf27x\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" npm ERR! npm ERR! gyp ERR! cwd D:\Program Files\nodejs\node_cache\_cacache\tmp\git-cloneuwf27x\node_modules\node-sass npm ERR! npm ERR! gyp ERR! node -v v14.20.0 npm ERR! npm ERR! gyp ERR! node-gyp -v v3.8.0 npm ERR! npm ERR! gyp ERR! not ok npm ERR! npm ERR! Build failed with error code: 1
最新发布
05-28
### 解决方案分析 在安装 `node-sass` 时遇到的错误可能与以下因素相关:Visual C++ 工具未正确安装、Python 版本不匹配或系统环境变量配置不当。以下是具体分析和解决方法: #### 1. **MSBUILD : error MSB3428 报错** 此错误表明系统未能加载 Visual C++ 组件 `VCBuild.exe`,通常是因为缺少必要的开发工具或路径配置问题[^5]。解决方法包括: - 安装 .NET Framework 2.0 SDK 或更高版本。 - 安装 Microsoft Visual Studio 2005 或更高版本(建议使用 Visual Studio Build Tools)。 - 如果组件已安装但路径未正确配置,请将其安装路径添加到系统环境变量中。 #### 2. **Python 2.7 环境变量缺失** `node-sass` 的编译依赖于 Python 2.7,若系统中未找到该版本的 Python,则会报错 `python2 not found`[^3]。解决方法如下: - 下载并安装 Python 2.7(注意不是 Python 3.x),确保安装路径被正确添加到系统的 PATH 环境变量中。 - 验证安装是否成功: ```bash python --version ``` 输出应为 `Python 2.7.x`。 #### 3. **msbuild exit code 1** 此错误通常是由于编译过程中出现的问题导致的,可能的原因包括: - 缺少必要的构建工具。 - 源代码无法从默认地址下载。 解决方法包括: - 安装 `windows-build-tools`,它会自动安装 Python 和 MSBuild 工具链: ```bash npm install --global --production windows-build-tools ``` - 配置淘宝镜像以加速资源下载: ```bash npm set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass ``` #### 4. **Node.js 和 node-gyp 版本兼容性** 如果使用的 Node.js 版本较新(如 v18.x),可能会与旧版本的 `node-sass` 不兼容[^5]。可以尝试以下方法: - 降级 Node.js 至 v16.x 或更低版本。 - 使用支持最新 Node.js 的 `sass` 替代 `node-sass`: ```bash npm uninstall node-sass npm install sass ``` #### 5. **完整解决方案步骤** 以下是综合上述方法的完整解决方案: 1. 安装必要工具: - 安装 Python 2.7 并配置 PATH。 - 安装 Visual Studio Build Tools。 2. 配置淘宝镜像: ```bash npm set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass ``` 3. 安装 `windows-build-tools`: ```bash npm install --global --production windows-build-tools ``` 4. 尝试重新安装 `node-sass`: ```bash npm install node-sass ``` 5. 若仍失败,考虑使用 `sass` 替代: ```bash npm uninstall node-sass npm install sass ``` ### 示例代码 以下是一个示例脚本,用于自动化部分配置和安装过程: ```bash # 步骤 1: 配置淘宝镜像 npm set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass # 步骤 2: 安装构建工具 npm install --global --production windows-build-tools # 步骤 3: 安装 node-sass npm install node-sass ``` ### 注意事项 - 确保所有工具的路径已被正确添加到系统环境变量中。 - 如果使用的是 Windows 系统,建议重启计算机以使环境变量生效。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值