node-sass

创建日期:2024-06-21
更新日期:2025-01-04

常见问题

1、执行yarn install报错:hylab-bladex\saber\node_modules\node-sass: Command failed.。

全部错误:

error E:\Project\燃气安全监管平台\hylab-bladex\saber\node_modules\node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: E:\Project\燃气安全监管平台\hylab-bladex\saber\node_modules\node-sass
Output:
Building: C:\Program Files\nodejs\node.exe E:\Project\燃气安全监管平台\hylab-bladex\saber\node_modules\node-sass\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   'E:\\Project\\燃气安全监管平台\\hylab-bladex\\saber\\node_modules\\node-sass\\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@20.9.0 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb download using dist-url https://npm.taobao.org/mirrors/node
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\anaconda3\python.exe"
gyp verb find Python - executing "D:\Python\anaconda3\python.exe" to get version
gyp verb find Python - version is "3.11.4"
gyp info find Python using Python version 3.11.4 found at "D:\Python\anaconda3\python.exe"
gyp verb get node dir no --target version specified, falling back to host node version: 20.9.0
gyp verb command install [ '20.9.0' ]
gyp verb download using dist-url https://npm.taobao.org/mirrors/node
gyp verb install input version string "20.9.0"
gyp verb install installing version: 20.9.0
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: 20.9.0
gyp verb build dir attempting to create "build" dir: E:\Project\燃气安全监管平台\hylab-bladex\saber\node_modules\node-sass\buildgyp verb build dir "build" dir needed to be created? E:\Project\燃气安全监管平台\hylab-bladex\saber\node_modules\node-sass\buildgyp verb find VS msvs_version was set from command line or npm config
gyp verb find VS - looking for Visual Studio version 2019
gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp verb find VS checking VS2019 (16.11.32126.315) found at:
gyp verb find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise"
gyp verb find VS - found "Visual Studio C++ core features"
gyp verb find VS - found VC++ toolset: v142
gyp verb find VS - found Windows SDK: 10.0.19041.0
gyp info find VS using VS2019 (16.11.32126.315) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise"
gyp info find VS run with --verbose for detailed information
gyp verb build/config.gypi creating config file
gyp ERR! UNCAUGHT EXCEPTION
gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#<Object>'
gyp ERR! stack     at createConfigFile (E:\Project\燃气安全监管平台\hylab-bladex\saber\node_modules\node-sass\node_modules\node-gyp\lib\configure.js:117:21)
gyp ERR! stack     at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "E:\\Project\\燃气安全监管平台\\hylab-bladex\\saber\\node_modules\\node-sass\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd E:\Project\燃气安全监管平台\hylab-bladex\saber\node_modules\node-sass
gyp ERR! node -v v20.9.0
gyp ERR! node-gyp -v v7.1.2

解决方法:先在package.json中,删除node-sass和sass-loader,然后执行以下代码。

yarn add node-sass -D
yarn add sass-loader -D

2、invalid mode: 'rU' while trying to load binding.gyp。

解决方法:设置sass的镜像为淘宝源。

npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass