fsd-nodejs / service-mw2

Node.js 全栈开发之 Midway.js 最佳实践

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

npm v7 执行 install 时会出现依赖报错

tree-lock opened this issue · comments

commented

npm v6 执行安装(本来用v7然后版本回退改用v6)

➜  service-mw2 git:(master) ✗ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: service-mw2@1.2.0
npm ERR! Found: @types/jest@26.0.24
npm ERR! node_modules/@types/jest
npm ERR!   dev @types/jest@"^26.0.24" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @types/jest@"^27.0.0" from ts-jest@27.0.5
npm ERR! node_modules/ts-jest
npm ERR!   dev ts-jest@"^27.0.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/xmo/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xmo/.npm/_logs/2021-09-06T10_18_18_436Z-debug.log
➜  service-mw2 git:(master) ✗ npm install npm@6 -g

removed 70 packages, changed 98 packages, and audited 438 packages in 6s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
➜  service-mw2 git:(master) ✗ npm install
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 core-js@2.6.12: core-js@<3.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. Please, upgrade your dependencies to the actual version of core-js.
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 resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated

> core-js@2.6.12 postinstall /home/xmo/code/demo/service-mw2/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> @midwayjs/cli@1.2.82 postinstall /home/xmo/code/demo/service-mw2/node_modules/@midwayjs/cli
> node ./postinstall

[midway] auto install complete
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN typeorm@0.2.37 requires a peer of @sap/hana-client@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of better-sqlite3@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of hdb-pool@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of mongodb@^3.6.0 but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of mssql@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of oracledb@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of pg@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of pg-native@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of pg-query-stream@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of redis@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of sql.js@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of sqlite3@* but none is installed. You must install peer dependencies yourself.
npm WARN typeorm@0.2.37 requires a peer of typeorm-aurora-data-api-driver@* but none is installed. You must install peer dependencies yourself.
npm WARN ts-node@10.2.1 requires a peer of @swc/core@>=1.2.50 but none is installed. You must install peer dependencies yourself.
npm WARN ts-node@10.2.1 requires a peer of @swc/wasm@>=1.2.50 but none is installed. You must install peer dependencies yourself.
npm WARN ts-jest@27.0.5 requires a peer of @types/jest@^27.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ts-jest@27.0.5 requires a peer of babel-jest@>=27.0.0 <28 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.5.4 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.5.4 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN jsdom@16.7.0 requires a peer of canvas@^2.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 2263 packages from 996 contributors in 253.695s

114 packages are looking for funding
  run `npm fund` for details

此处是 npm@7 错误重现。

➜  service-mw2 git:(master) ✗ npm -v
7.22.0
➜  service-mw2 git:(master) ✗ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: service-mw2@1.2.0
npm ERR! Found: @types/jest@26.0.24
npm ERR! node_modules/@types/jest
npm ERR!   dev @types/jest@"^26.0.24" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @types/jest@"^27.0.0" from ts-jest@27.0.5
npm ERR! node_modules/ts-jest
npm ERR!   dev ts-jest@"^27.0.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/xmo/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xmo/.npm/_logs/2021-09-06T10_25_46_161Z-debug.log

虽然应该是 npm 的问题,但还是给遇到相似问题的人一些提示。如果遇到类似问题,npm install -g npm@6 版本回退即可;
另外,用yarn安装是不会产生问题的。

👍

@darkXmo 更新了依赖列表,你可以用 npm@7 试试看安装依赖正常了没有。

commented

@darkXmo 更新了依赖列表,你可以用 npm@7 试试看安装依赖正常了没有。

换了个错误报,过于痛苦,我还是选择 yarn 来安装依赖吧。

npm ERR! code 1
npm ERR! path /home/xmo/code/demo/service-mw2/node_modules/sqlite3
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@14.17.3 | linux | x64
npm ERR! gyp info spawn /usr/bin/python2
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/home/xmo/code/demo/service-mw2/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/xmo/code/demo/service-mw2/node_modules/sqlite3/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/xmo/code/demo/service-mw2/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/xmo/.node-gyp/14.17.3/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/home/xmo/.node-gyp/14.17.3',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/home/xmo/code/demo/service-mw2/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/home/xmo/.node-gyp/14.17.3/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/home/xmo/code/demo/service-mw2/node_modules/sqlite3',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/home/xmo/code/demo/service-mw2/node_modules/node-gyp/lib/configure.js:345:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:375:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Linux 5.10.16.3-microsoft-standard-WSL2
npm ERR! gyp ERR! command "/home/xmo/.nvm/versions/node/v14.17.3/bin/node" "/home/xmo/code/demo/service-mw2/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /home/xmo/code/demo/service-mw2/node_modules/sqlite3
npm ERR! gyp ERR! node -v v14.17.3
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xmo/.npm/_logs/2021-09-13T08_25_21_464Z-debug.log

这个看上去显示 gyp 的问题

安装 sqlite3 会依赖 node-gyp,windows 平台不大容易装上,可能需要安装 Visual Studio (非VSCode)。你是 MacOS 吧应该没问题。
我这儿 CI 的 alpine 镜像用 npm7 安装是正常的,你可以参考下:

  1. 安装 python3 ,比如 apk add python3
  2. 设置路径, npm config set python /usr/bin/python3
  3. 项目安装依赖 npm i --legacy-peer-deps