在 react-native 应用程序中安装 date-fns 错误后,纱线启动失败

Posted

技术标签:

【中文标题】在 react-native 应用程序中安装 date-fns 错误后,纱线启动失败【英文标题】:yarn start fails after error in installing date-fns in react-native app 【发布时间】:2020-11-03 13:09:17 【问题描述】:

对于日期格式,我尝试通过以下方式下载 date-fns:npm install date-fns --save

安装失败,我收到以下警告和错误:

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
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated core-js@1.2.7: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated babel-preset-expo@8.1.1: 8.1.1 mistakenly contains the contents of 8.2.1; use that version instead
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated intl-relativeformat@2.2.0: This package has been deprecated, please see migration guide at 'https://github.com/formatjs/formatjs/tree/master/packages/intl-relativeformat#migration-guide'
npm WARN deprecated @hapi/joi@15.1.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated deep-assign@3.0.0: Check out `lodash.merge` or `merge-options` instead.
npm WARN rm not removing C:\Users\kanch\Documents\ReactNative\confusion\node_modules\.bin\rimraf.cmd as it wasn't installed by C:\Users\kanch\Documents\ReactNative\confusion\node_modules\rimraf
npm WARN rm not removing C:\Users\kanch\Documents\ReactNative\confusion\node_modules\.bin\rimraf as it wasn't installed by C:\Users\kanch\Documents\ReactNative\confusion\node_modules\rimraf
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^2.1.2 (node_modules\jest-haste-map\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\metro\node_modules\jest-haste-map\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\metro-core\node_modules\jest-haste-map\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\metro\node_modules\jest-haste-map\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")
npm WARN react-native-elements@2.0.2 requires a peer of react-native-vector-icons@>6.6.0 but none is installed. You must install peer dependencies yourself.

npm ERR! Maximum call stack size exceeded

之后我把它留在那里并保存了应用程序而不格式化日期并尝试运行yarn start,我得到了这个输出:

  throw err;
  ^

Error: Cannot find module 'nice-try'
Require stack:
- C:\Users\kanch\Documents\ReactNative\confusion\node_modules\expo\node_modules\cross-spawn\lib\parse.js
- C:\Users\kanch\Documents\ReactNative\confusion\node_modules\expo\node_modules\cross-spawn\index.js
- C:\Users\kanch\Documents\ReactNative\confusion\node_modules\expo\bin\cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at Object.<anonymous> (C:\Users\kanch\Documents\ReactNative\confusion\node_modules\expo\node_modules\cross-spawn\lib\parse.js:4:17)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Module.require (internal/modules/cjs/loader.js:1089:19) 
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\kanch\\Documents\\ReactNative\\confusion\\node_modules\\expo\\node_modules\\cross-spawn\\lib\\parse.js',
    'C:\\Users\\kanch\\Documents\\ReactNative\\confusion\\node_modules\\expo\\node_modules\\cross-spawn\\index.js',
    'C:\\Users\\kanch\\Documents\\ReactNative\\confusion\\node_modules\\expo\\bin\\cli.js'
  ]

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我无法启动 Metro 服务器,并且在我的 node_modules 中找不到 nice-try。有什么解决办法吗?

【问题讨论】:

【参考方案1】:

你试过删除 node_modules 和 package-lock.json 然后npm install?

【讨论】:

不,但您的意思是删除 node_modules 整个文件夹吗?我用纱线做了create-react-native-app,所以这个问题与此有关吗? 是的,node_modules 整个文件夹。由于 npm install date-fns --save 存在问题,因此它可能损坏了某些依赖关系树。所以删除它并进行新的纱线安装应该清理并重新安装它。 它工作但我丢失了 node_modules 中的 .bin 文件夹,并且这个错误在 android 手机上弹出:React Native version mismatch. javascript version: 0.63.1 Native version: 0.62.2 在 Web 浏览器上运行时,它无法编译显示:Module not found: Can't resolve 'react-native-web/dist/exports/DatePickerAndroid' in 'C:\Users\kanch\Documents\ReactNative\confusion\node_modules\react-native-datepicker 如何解决这些? 你使用的是 npm install 还是 yarn install? npm install 创建一个名为 package-lock.json 的文件,而 yarn install 创建 yarn.lock 文件,这些文件保留了最后一个版本安装。因此,您必须使用 node_modules 删除这两个文件,然后使用 yarn 或 npm 进行包安装。不要同时使用两者。尝试这样做,希望它能解决版本控制问题。 好的!我正在使用 yarn 来安装软件包,但在上次安装中我使用了 npm,这可能导致了所有早期的错误。我通过引用 package.json 文件来安装所有的包。

以上是关于在 react-native 应用程序中安装 date-fns 错误后,纱线启动失败的主要内容,如果未能解决你的问题,请参考以下文章

无法在 anaconda 中安装 turicreate

当我在项目应用程序中安装并链接 react-native-admob 在加载时崩溃

Xcode 9 错误在本地存储中安装 Realm 后

文件保存意图,如共享意图 Android/iOS react-native

React-native iOS 不显示图像(pod 问题)

Atom : React Native 的快速文档