为什么我在这个 repo 中出现 npm install 大量错误

Why do I get npm install massive error in this repo

我想使用这个 react-file-viewer 但我无法使用 运行。当我做 npm install 时,我得到了巨大的错误。我是新手。

我的Node版本是v16.9.1

这个项目是旧的,我认为它是为较旧的 Node 版本创建的,所以它有很多错误我不知道从哪里开始。如果我将所有 package.json 依赖项更新到最新版本,你认为它可以工作吗?

PS C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master> npm install
npm WARN deprecated babel-preset-es2015@6.24.1:   Thanks for using Babel: we recommend using babel-preset-env now: please read https://babeljs.io/env to update!
npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
npm WARN deprecated kleur@2.0.2: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s).
npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
npm WARN deprecated eslint-loader@1.9.0: This loader has been deprecated. Please use eslint-webpack-plugin
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm WARN deprecated html-webpack-plugin@2.30.1: out of support
npm WARN deprecated sane@2.5.2: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
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 WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated svgo@0.7.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
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 WARN deprecated core-js@2.6.12: core-js@<3.4 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. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:\Program Files\nodejs\node.exe C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   'C:\Program Files\nodejs\node.exe',
npm ERR! gyp verb cli   'C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\node-gyp\bin\node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@16.9.1 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` succeeded python C:\Python39\python.EXE
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Command failed: C:\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack                       ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! gyp ERR! stack
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:397:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
npm ERR! gyp ERR! System Windows_NT 10.0.19042
npm ERR! gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.9.1
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Local\npm-cache\_logs21-12-25T08_40_04_195Z-debug.log
PS C:\Users\user\Downloads\react-file-viewer-master (1)\react-file-viewer-master>

安装 node-sass 期间 运行ning node-gyp 时发生错误,如您在错误中所见。错误日志中还提到,您很可能没有安装 Python。

尝试运行宁node-gyp rebuild

如果失败,则表示设置不正确。按照 node-gyp documentation 正确设置您的环境,然后重新 运行 npm install.

此外,请查看 node-sass 支持的 Node 版本。

看起来 Python 有问题。

你能运行下面看看是否有帮助吗,

npm install express

否则,请尝试以下

删除node_modulesfolder

运行 npm install --global windows-build-tools 具有管理权限。

使用 npm install

重新安装节点模块或节点-sass

突出显示错误日志中的一些错误行

npm ERR! gyp verb checks python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2

npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack                       ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax

这简单的意思是,进程正在寻找 Python v2.x 但找不到。因此,继续使用计算机上的 Python v3.9。但是,然后他们点击了 print 语句,该语句在 Python v3.x 中无效(但在 Python v2.x 中有效)

你可以做

  1. 安装 Python v2.x(与 Python v3.x 并排)。
  2. 更新 node-sass(正如我在您的一条评论中看到的那样,您已经这样做了)。