在旧项目上更新或安装npm时出现npm依赖项错误

t98cgbkg  于 2023-08-06  发布在  其他
关注(0)|答案(2)|浏览(201)

有一个非常旧的项目,我试图运行,每当我尝试npm安装或启动项目时,它会给出各种依赖项错误,特别是过时的npm版本的错误,我有最新版本的node(16.x),而这个项目有过时的(14.x)版本的node。npm更新也不起作用,有什么建议我如何运行这个项目?这是'npm install'的日志文件

0 verbose cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
1 info using npm@8.15.0
2 info using node@v16.17.1
3 timing npm:load:whichnode Completed in 1ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:C:\Program Files\nodejs\node_modules\npm\npmrc Completed in 3ms
6 timing config:load:builtin Completed in 3ms
7 timing config:load:cli Completed in 2ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:D:\FYP\Project Frontend\fyp\.npmrc Completed in 0ms
10 timing config:load:project Completed in 2ms
11 timing config:load:file:C:\Users\Administrator\.npmrc Completed in 0ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Users\Administrator\AppData\Roaming\npm\etc\npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 2ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 14ms
19 timing npm:load:configload Completed in 14ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 1ms
22 verbose title npm install
23 verbose argv "install"
24 timing npm:load:setTitle Completed in 2ms
25 timing config:load:flatten Completed in 4ms
26 timing npm:load:display Completed in 6ms
27 verbose logfile logs-max:10 dir:C:\Users\Administrator\AppData\Local\npm-cache\_logs
28 verbose logfile C:\Users\Administrator\AppData\Local\npm-cache\_logs\2022-10-12T16_19_59_564Z-debug-0.log
29 timing npm:load:logFile Completed in 11ms
30 timing npm:load:timers Completed in 0ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 36ms
33 timing arborist:ctor Completed in 1ms
34 silly logfile start cleaning logs, removing 2 files
35 silly logfile done cleaning log files
36 timing idealTree:init Completed in 1762ms
37 warn old lockfile
37 warn old lockfile The package-lock.json file was created with an old version of npm,
37 warn old lockfile so supplemental metadata must be fetched from the registry.
37 warn old lockfile
37 warn old lockfile This is a one-time fix-up, please be patient...
37 warn old lockfile

字符串
这里有个错误

npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: undefined,
npm WARN EBADENGINE   required: { node: '14.x' },
npm WARN EBADENGINE   current: { node: 'v16.17.1', npm: '8.15.0' }
npm WARN EBADENGINE }
npm WARN deprecated @types/classnames@2.3.1: This is a stub types definition. classnames provides its own type definitions, so you do not need this installed.
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
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 WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
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 @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
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 hoek@4.2.1: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated mini-create-react-context@0.4.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm WARN deprecated redux-devtools-extension@2.13.9: Package moved to @redux-devtools/extension.
npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated eslint-loader@3.0.3: This loader has been deprecated. Please use eslint-webpack-plugin
npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
npm WARN deprecated html-webpack-plugin@4.0.0-beta.11: please switch to a stable version
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.

ngynwnxp

ngynwnxp1#

方案1(推荐)

我建议使用一个名为nvm的工具来切换node和npm的版本。顺便说一下,你不必升级/降级整个项目的依赖关系。这是一个最小的解决方案,它将工作在进一步的项目。
要安装nvm,请检查here中的 table of contents 部分。
安装nvm后:

第一步

  • 正在安装所需的节点版本 *

nvm install v14.18.0

  • 您也可以通过此命令检查支持的版本 *

nvm ls-remote

第二步

  • 切换版本 *

nvm use v14.18.0

第三步

npm install

方案二

这是更痛苦的,因为你必须重复每个项目的步骤。

  • 将您的节点版本降级为“14.x.x”
  • 删除package-lock.json(因为您为新版本的节点安装了它)
  • 并安装依赖项。
  • 并对不同版本的项目重复这些步骤。
xfb7svmp

xfb7svmp2#

我完全同意Batuhan的回答,我想为那些寻求为旧项目安装npm依赖的人添加一些关于这个问题的补充信息。
当终端显示以下消息时,表示您设备上当前使用的npm版本与package-lock.json文件所需的npm版本不匹配。

npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.

字符串
您可以检查package-lock.json文件中的'lockfilevision',然后确定所需的正确npm版本。https://docs.npmjs.com/cli/v9/configuring-npm/package-lock-json#lockfileversion
接下来,您可以验证兼容的Node.js版本并使用nvm安装它。https://nodejs.org/en/download/releases

相关问题