如何解决: PS F:\codefuntest> yarn install yarn install v1.22.19 info No lockfile found.…
- User
如何解决: PS F:\codefuntest> yarn install yarn install v1.22.19 info No lockfile found. [1/4] Resolving packages... warning node-sass > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning node-sass > node-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 warning node-sass > request > har-validator@5.1.5: this library is no longer supported warning node-sass > request > 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. warning react-scripts > babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates. warning react-scripts > babel-preset-react-app > @babel/plugin-proposal-nullish-coalescing-operator@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-nullish-coalescing-operator instead. warning react-scripts > babel-preset-react-app > @babel/plugin-proposal-numeric-separator@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-numeric-separator instead. warning react-scripts > babel-preset-react-app > @babel/plugin-proposal-private-methods@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-private-methods instead. warning react-scripts > babel-preset-react-app > @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead. warning react-scripts > babel-preset-react-app > @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. warning react-scripts > webpack-dev-server > chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies warning react-scripts > webpack-dev-server > chokidar > fsevents@1.2.13: The v1 package contains DANGEROUS / INSECURE binaries. Upgrade to safe fsevents v2 warning react-scripts > webpack-dev-server > webpack-log > 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. warning react-scripts > workbox-webpack-plugin > source-map-url@0.4.1: See warning react-scripts > workbox-webpack-plugin > workbox-build > source-map-url@0.4.1: See warning react-scripts > @pmmmwh/react-refresh-webpack-plugin > native-url > querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. warning react-scripts > @svgr/webpack > @svgr/plugin-svgo > svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x. warning react-scripts > terser-webpack-plugin > cacache > @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi@15.1.1: Switch to 'npm install joi' warning react-scripts > workbox-webpack-plugin > workbox-build > rollup-plugin-babel@4.4.0: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-babel. warning react-scripts > workbox-webpack-plugin > workbox-build > rollup-plugin-terser@5.3.1: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser warning react-scripts > webpack > watchpack > watchpack-chokidar2 > chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies warning react-scripts > @svgr/webpack > @svgr/plugin-svgo > svgo > 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: warning react-scripts > babel-jest > @jest/transform > jest-haste-map > sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added warning react-scripts > webpack > micromatch > snapdragon > source-map-resolve@0.5.3: See warning react-scripts > resolve-url-loader > rework > css > source-map-resolve@0.5.3: See warning react-scripts > webpack > micromatch > snapdragon > source-map-resolve > source-map-url@0.4.1: See warning react-scripts > optimize-css-assets-webpack-plugin > cssnano > cssnano-preset-default > postcss-svgo > svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x. warning react-scripts > postcss-preset-env > postcss-color-functional-notation > postcss-values-parser > flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash. warning react-scripts > resolve-url-loader > rework > css > urix@0.1.0: Please see warning react-scripts > webpack > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/address@2.1.4: Moved to 'npm install @sideway/address' warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/topo > @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained warning react-scripts > webpack > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: warning react-scripts > workbox-webpack-plugin > workbox-build > @surma/rollup-plugin-off-main-thread > magic-string > sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead warning react-scripts > workbox-webpack-plugin > workbox-build > strip-comments > babel-plugin-transform-object-rest-spread > babel-runtime > 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, feature 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. warning react-scripts > jest > @jest/core > jest-config > jest-environment-jsdom > jsdom > w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin. [2/4] Fetching packages... [3/4] Linking dependencies... warning "craco-less > less-loader@7.3.0" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0". warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta". warning "@craco/craco > cosmiconfig-typescript-loader@1.0.9" has unmet peer dependency "@types/node@". warning "@craco/craco > cosmiconfig-typescript-loader > ts-node@10.9.1" has unmet peer dependency "typescript@>=2.7". warning " > @testing-library/user-event@12.8.3" has unmet peer dependency "@testing-library/dom@>=7.21.4". [4/4] Building fresh packages... [-/6] ⠠ waiting... [-/6] ⠐ waiting... [3/6] ⠐ node-sass [-/6] ⠐ waiting... error F:\codefuntest\node_modules\node-sass: Command failed. Exit code: 1 Command: node scripts/build.js Arguments: Directory: F:\codefuntest\node_modules\node-sass Output: Building: C:\Program Files\nodejs\node.exe F:\codefuntest\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= gyp info it worked if it ends with ok gyp verb cli [ gyp verb cli 'C:\Program Files\nodejs\node.exe', gyp verb cli 'F:\codefuntest\node_modules\node-gyp\bin\node-gyp.js', gyp verb cli 'rebuild', gyp verb cli '--verbose', gyp verb cli '--libsass_ext=', gyp verb cli '--libsass_cflags=', gyp verb cli '--libsass_ldflags=', gyp verb cli '--libsass_library=' gyp verb cli ] gyp info using node-gyp@7.1.2 gyp info using node@18.12.1 | win32 | x64 gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp verb command configure [] gyp verb find Python Python is not set from command line or npm configuration gyp verb find Python Python is not set from environment variable PYTHON gyp verb find Python checking if "python3" can be used gyp verb find Python - executing "python3" to get executable path gyp verb find Python - "python3" is not in PATH or produced an error gyp verb find Python checking if "python" can be used gyp verb find Python - executing "python" to get executable path gyp verb find Python - executable path is "D:\python\python.exe" gyp verb find Python - executing "D:\python\python.exe" to get version gyp verb find Python - version is "3.10.9" gyp info find Python using Python version 3.10.9 found at "D:\python\python.exe" gyp verb get node dir no --target version specified, falling back to host node version: 18.12.1 gyp verb command install [ '18.12.1' ] gyp verb install input version string "18.12.1" gyp verb install installing version: 18.12.1 gyp verb install --ensure was passed, so won't reinstall if already installed gyp verb install version is already installed, need to check "installVersion" gyp verb got "installVersion" 9 gyp verb needs "installVersion" 9 gyp verb install version is good gyp verb get node dir target node version installed: 18.12.1 gyp verb build dir attempting to create "build" dir: F:\codefuntest\node_modules\node-sass\build gyp verb build dir "build" dir needed to be created? F:\codefuntest\node_modules\node-sass\build gyp verb find VS msvs_version not set from command line or npm config gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt gyp verb find VS unknown version "undefined" found at "C:\Program Files\Microsoft Visual Studio\2022\Community" gyp verb find VS unknown version "undefined" found at "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" gyp verb find VS could not find a version of Visual Studio 2017 or newer to use gyp verb find VS looking for Visual Studio 2015 gyp verb find VS - not found gyp verb find VS not looking for VS2013 as it is only supported up to Node.js 8 gyp ERR! find VS gyp ERR! find VS msvs_version not set from command line or npm config gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt gyp ERR! find VS unknown version "undefined" found at "C:\Program Files\Microsoft Visual Studio\2022\Community" gyp ERR! find VS unknown version "undefined" found at "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use gyp ERR! find VS looking for Visual Studio 2015 gyp ERR! find VS - not found gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 gyp ERR! find VS gyp ERR! find VS ************************************************************** gyp ERR! find VS You need to install the latest version of Visual Studio gyp ERR! find VS including the "Desktop development with C++" workload. gyp ERR! find VS For more information consult the documentation at: gyp ERR! find VS gyp ERR! find VS ************************************************************** gyp ERR! find VS gyp ERR! configure error gyp ERR! stack Error: Could not find any Visual Studio installation to use gyp ERR! stack at VisualStudioFinder.fail (F:\codefuntest\node_modules\node-gyp\lib\find-visualstudio.js:121:47) gyp ERR! stack at F:\codefuntest\node_modules\node-gyp\lib\find-visualstudio.js:74:16 gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (F:\codefuntest\node_modules\node-gyp\lib\find-visualstudio.js:351:14) gyp ERR! stack at F:\codefuntest\node_modules\node-gyp\lib\find-visualstudio.js:70:14 gyp ERR! stack at F:\codefuntest\node_modules\node-gyp\lib\find-visualstudio.js:372:16 gyp ERR! stack at F:\codefuntest\node_modules\node-gyp\lib\util.js:54:7 gyp ERR! stack at F:\codefuntest\node_modules\node-gyp\lib\util.js:33:16 gyp ERR! stack at ChildProcess.exithandler (node:child_process:420:5) gyp ERR! stack at ChildProcess.emit (node:events:513:28) gyp ERR! stack at maybeClose (node:internal/child_process:1091:16) gyp ERR! System Windows_NT 10.0.22621 gyp ERR! command "C:\Program Files\nodejs\node.exe" "F:\codefuntest\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd F:\codefuntest\node_modules\node-sass gyp ERR! node -v v18.12.1 - Assistant
根据你提供的错误日志,这里的主要问题是在尝试构建
node-sass模块时失败了。详细来说,node-gyp(编译本地扩展的一个工具)需要找到一个适当版本的 Visual Studio 来编译 C++ 代码,但是它没能找到。node-sass的编译依赖于 Python 和 C++ 的编译环境。这里的错误显示你可能没有适当的 Visual Studio 版本,或者它没有找到。这里有几个步骤可以尝试解决此问题:
-
安装 Windows 构建工具: 打开命令行界面(以管理员身份),运行以下命令:
npm install --global windows-build-toolswindows-build-tools将会安装 Visual Studio 的构建工具和必要的 Python 版本。 -
使用
node-sass的替代品(例如sass或dart-sass):node-sass是 Sass 的一个实现,但是它依赖于二进制编译。它的替代品sass或者说dart-sass提供相同的功能,但是是用纯 Dart 语言编写的,不需要编译。若要使用
sass而不是node-sass,你可以在package.json中更改依赖,并从项目中移除node-sass:yarn remove node-sass yarn add sass -
手动指定Visual Studio版本: 如果你已经安装了 Visual Studio,可能需要指定版本。你可以通过设置环境变量来手动选择一个 MSVS 版本:
setx GYP_MSVS_VERSION 2019
-
- User
(c) Microsoft Corporation. All rights reserved.
C:\Windows\System32>npm install --global windows-build-tools npm WARN deprecated har-validator@5.1.5: this library is no longer supported 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 for details. npm WARN deprecated request@2.88.2: request has been deprecated, see npm WARN deprecated windows-build-tools@5.2.2: Node.js now includes build tools for Windows. You probably no longer need this tool. See for details. npm ERR! code 1 npm ERR! path C:\Users\30388\AppData\Roaming\npm\node_modules\windows-build-tools npm ERR! command failed npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node ./dist/index.js Downloading python-2.7.15.amd64.msi npm ERR! [============================================>] 100.0% of 20.2 MB (3.52 MB/s) npm ERR! Downloaded python-2.7.15.amd64.msi. Saved to C:\Users\30388.windows-build-tools\python-2.7.15.amd64.msi. Downloading vs_BuildTools.exe npm ERR! [============================================>] 100.0% of 1.12 MB (1.12 MB/s) npm ERR! Downloaded vs_BuildTools.exe. Saved to C:\Users\30388.windows-build-tools\vs_BuildTools.exe. npm ERR! npm ERR! Starting installation... npm ERR! Downloading installers failed. Error: TypeError: 'process.env' only accepts a configurable, writable, and enumerable data descriptor npm ERR! at Function.defineProperty () npm ERR! at Object.removePath (C:\Users\30388\AppData\Roaming\npm\node_modules\windows-build-tools\dist\utils\remove-path.js:11:12) npm ERR! at Object.install (C:\Users\30388\AppData\Roaming\npm\node_modules\windows-build-tools\dist\install\index.js:29:19) npm ERR! at C:\Users\30388\AppData\Roaming\npm\node_modules\windows-build-tools\dist\start.js:17:19 npm ERR! at Object.download (C:\Users\30388\AppData\Roaming\npm\node_modules\windows-build-tools\dist\download.js:35:5) npm ERR! at process.processTicksAndRejections (node:internal/process/task_queues:95:5) npm ERR! at async Object.aquireInstallers (C:\Users\30388\AppData\Roaming\npm\node_modules\windows-build-tools\dist\aquire-installers.js:32:13) { npm ERR! code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY' npm ERR! } npm ERR! windows-build-tools will now exit.
- Assistant
从您贴出的错误日志来看,尝试使用
windows-build-tools安装构建工具失败了。错误提示表明这个包已经过时,而且有可能你的系统上已经有了所需的工具。确实,windows-build-tools是为了方便早期版本的 Node.js 用户在 Windows 上安装构建工具,但现在 Node.js 已经包括了所需的构建工具。此外,对于这个错误,它似乎尝试安装 Python 2.7,这是一个陈旧的版本,而 Node.js 和
node-gyp实际上现在需要 Python 3。根据最新的情况,可以尝试以下步骤来安装必要的工具:
-
安装最新版的 Node.js: 如果你还没有安装最新版本的 Node.js,请更新它,因为最新版本的 Node.js已经包含了在 Windows 上编译原生模块所需的工具链。
-
使用 Visual Studio 社区版: 如果你没有最新版的 Node.js,或者你正在使用较旧的版本,那么你可能需要单独安装构建工具。推荐安装 Visual Studio 2019 或 2022 社区版,并在安装过程中选择“使用 C++ 的桌面开发”工作负载。
-
安装最新的 Python 3: 你也需要安装 Python 3,因为
node-gyp依赖于它。你可以从 Python 官方网站下载并安装 Python 3 的最新版。安装时,确保选中“Add Python to PATH”的选项。 -
配置
npm使用 Python 3: 安装好 Python 3 后,你需要配置npm使用 Python 3。你可以运行以下命令来配置npm:npm config set python "path\to\python3"替换
"path\to\python3"为你的 Python 3 安装路径,例如 。
-