反应本机 | 错误:无法解析 node_modules/react-native/index.js 中的模块

Ant*_*örl 28 ios node-modules reactjs react-native

每当我使用react-native run-ios运行我的React Native应用程序时,我都会收到以下错误:

错误:无法从 /Users/antonhorl3/WebstormProjects/sagly/client/node_modules/react-native/index.js 解析模块 ./Libraries/Components/DatePicker/DatePickerIOS:

这些文件都不存在:node_modules/react-native/Libraries/Components/DatePicker/DatePickerIOS(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native。 tsx|.tsx)node_modules/react-native/Libraries/Components/DatePicker/DatePickerIOS/index(.native|.native.js|.js|.native.json|.json|.native.ts|.ts|.native .tsx|.tsx) 15 | 从 './Libraries/Components/ActivityIndi​​cator/ActivityIndi​​cator' 导入 ActivityIndi​​cator 类型;16 | 16 从 './Libraries/Components/Button' 导入 typeof Button;17 | 17 从 './Libraries/Components/DatePicker/DatePickerIOS' 导入 DatePickerIOS 类型;| ^ 18 | 从'./Libraries/Components/DrawerAndroid/DrawerLayoutAndroid'导入DrawerLayoutAndroid类型;19 | 19 从 './Libraries/Lists/FlatList' 导入 FlatList 类型;20 | 从'./Libraries/Image/Image'导入图像类型;在ModuleResolver.resolveDependency(/Users/antonhorl3/WebstormProjects/sagly/client/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:107:15 )在 DependencyGraph.resolveDependency (/Users/antonhorl3/WebstormProjects/sagly/client/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph.js:288:43)在 Object.resolve (/Users/antonhorl3/WebstormProjects/sagly/client/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/lib/transformHelpers.js:129:24) 处解析 ( /Users/antonhorl3/WebstormProjects/sagly/client/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/traverseDependency.js:396:33)位于/Users/antonhorl3/WebstormProjects/ sagly/client/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/traverseDependency.js:412:26 at Array.reduce () atsolveDependencies (/Users/antonhorl3/WebstormProjects/ sagly/client/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/traverseDependency.js:411:33) 在 processModule (/Users/antonhorl3/WebstormProjects/sagly/client/node_modules) /@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/traverseDependency.js:140:31) 在异步 addDependency (/Users/antonhorl3/WebstormProjects/sagly/client/node_modules/@react- native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/traverseDependency.js:230:18) 在 async Promise.all (索引 0)`

我没有对我的代码进行任何更改,问题只是出现了。我确实更新了 Xcode,这只是我认为我所做的唯一更改。我很失落。

React-Native模块中的导入语句是正确的,并且该文件确实存在。

这是我的环境:

 System:
    OS: macOS 13.2.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 40.24 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.1.2 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK:
      API Levels: 23, 26, 29, 30, 31
      Build Tools: 19.1.0, 23.0.1, 23.0.3, 27.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 33.0.0
      System Images: android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7199119
    Xcode: 14.3/14E222b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.17 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: 5.0.1-alpha.2 => 5.0.1-alpha.2 
    react: 18.0.0-rc.0 => 18.0.0-rc.0 
    react-native: 0.65.3 => 0.65.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,我很乐意添加或编辑我的问题。

谢谢您的帮助。

我尝试过的:

  • 重新启动我的笔记本电脑
  • 反应本机启动 -- --reset-cache
  • rm -rf /tmp/metro-*
  • 纱线启动--重置缓存
  • 守望者 守望者
  • 删除node_modules并重新安装它们

应用程序运行时应该不会出现此错误。

这是我的 package.json:

 System:
    OS: macOS 13.2.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 40.24 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.1.2 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK:
      API Levels: 23, 26, 29, 30, 31
      Build Tools: 19.1.0, 23.0.1, 23.0.3, 27.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 33.0.0
      System Images: android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7199119
    Xcode: 14.3/14E222b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.17 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: 5.0.1-alpha.2 => 5.0.1-alpha.2 
    react: 18.0.0-rc.0 => 18.0.0-rc.0 
    react-native: 0.65.3 => 0.65.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
Run Code Online (Sandbox Code Playgroud)

小智 13

XCode 版本 14.3 存在一个已知问题。请参阅https://github.com/facebook/react-native/issues/36635

  • 版本 15 上出现同样的错误:( (3认同)