【发布时间】:2022-01-14 19:06:31
【问题描述】:
我正在尝试清理我的 react-native 项目的包,以便在基于 MacOS 的系统上进行干净的 npm 安装(我用于 Android 开发的 Windows 系统在清理包版本方面没有问题)。
我开始在 npm 安装中看到错误,抱怨不兼容的版本差异,并列出了“rook 项目”和 node_modules/ 目录中每个包的版本之间的差异。
我通过删除 package-lock.json 进行常规修复,删除 node_modules 目录并重新运行 npm install。从我的项目文件夹中。它立即提出了同样的错误投诉。问题是这样,我的项目文件夹中没有 node_modules ,因为我删除了它。并且它没有创建新的 node_modules 目录。
鉴于这个问题,我该如何调试和修复它?我想知道的问题:
- 如何告诉 npm 告诉我它认为根项目的价值是什么(完整路径)?
- 如何告诉 npm 告诉我它似乎看到的 node_modules 目录的完整路径在哪里?
- 最后,我如何强制 npm 做正确的事情并专注于我的项目的附属品,而不是像看起来那样查看项目文件夹之外?
我的一些想法。我不明白为什么要在根项目和 node_modules 之间进行包 cersion 比较?
似乎 nodde 和 npm 在 MacOS 环境中做的事情与在我的 windows 系统环境中做的事情不同——我不明白这个。
这里的任何人都可以帮助我了解发生了什么以及如何解决它?
此处的错误输出:
thomas@Presonus americanaradio % npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: AmericanaRadio@0.0.2
npm ERR! Found: react@16.14.0
npm ERR! node_modules/react
npm ERR! react@"^16.13.1" from the root project
npm ERR! peer react@"^16.8" from
@react-native-community/async-storage@1.12.1
npm ERR! node_modules/@react-native-community/async-storage
npm ERR! @react-native-community/async-storage@"^1.12.1" from the
root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.2" from react-native@0.66.4
npm ERR! node_modules/react-native
npm ERR! react-native@"^0.66.3" from the root project
npm ERR! peer react-native@">=0.59" from
@react-native-community/async-storage@1.12.1
npm ERR! node_modules/@react-native-community/async-storage
npm ERR! @react-native-community/async-storage@"^1.12.1" 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 /Users/thomas/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/thomas/.npm/_logs/2021-12-10T15_47_02_669Z-debug.log
thomas@Presonus americanaradio %
这里的package.json内容:
{END)
"name": "AmericanaRadio",
"version": "0.0.2",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/async-storage": "^1.12.1",
"@react-native-community/checkbox": "^0.5.2",
"@react-native-community/masked-view": "^0.1.10",
"@react-native-community/slider": "^3.0.3",
"node-fetch": "^2.6.1",
"react": "^16.13.1",
"react-native": "^0.66.3",
"react-native-background-timer": "^2.4.1",
"react-native-elements": "^3.4.2",
"react-native-gesture-handler": "^1.9.0",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-reanimated": "^2.2.4",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.15.2",
"react-native-simple-survey": "^3.1.2",
"react-native-swift": "^1.2.1",
"react-native-vector-icons": "^8.0.0",
"react-native-version-check": "^3.4.2",
"react-native-version-info": "^1.1.0",
"react-native-webview": "^11.3.1",
"react-navigation": "^4.4.3",
"react-navigation-drawer": "^2.6.0",
"react-navigation-stack": "^2.10.2",
"react-usestateref": "^1.0.8",
"socket.io-client": "^4.4.0"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "^7.18.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"react-test-renderer": "16.13.1"
},
"jest": {
"preset": "react-native"
}
}
~
(END)
如我的描述中所述,node_modules 目录已被删除并且运行 npm install 失败并且没有创建 node_modules 目录。因此,错误消息令人困惑,因为我的项目目录中没有包(americanaradio)。
感谢您查看此内容,希望可以从中找到解决方案。
【问题讨论】:
-
你应该列出你在
npm install得到的错误 -
您不应该删除 package-lock.json,它会保留实际安装的依赖项。
-
请在您的问题中附上错误日志详细信息
标签: node.js react-native npm