开发者问题收集

错误:错误:无法从 /node_modules/react-native-reanimated/src/reanimated2/index.ts 解析模块 ./Hooks

2021-10-26
2326

我新安装了 React Native Reanimated 2.3.0-beta.1,并且已经按照文档中的设置进行操作。

"react-native-gesture-handler": "^1.10.3",
"react-native-reanimated": "^2.3.0-beta.2",

当启动我的应用程序时,出现以下错误:

error: Error: Unable to resolve module ./Hooks from /ProjectName/node_modules/react-native-reanimated/src/reanimated2/index.ts: 
None of these files exist:
* node_modules/react-native-reanimated/src/reanimated2/Hooks(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.svg|.native.svg|.svg)
* node_modules/react-native-reanimated/src/reanimated2/Hooks/index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.svg|.native.svg|.svg)
> 1 | export * from './core';
  2 | export * from './hook';
  3 | export * from './animation';
  4 | export * from './interpolation';
    at ModuleResolver.resolveDependency (/ProjectName/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:107:15)
    at DependencyGraph.resolveDependency (/ProjectName/node_modules/metro/src/node-haste/DependencyGraph.js:288:43)
    at Object.resolve (/ProjectName/node_modules/metro/src/lib/transformHelpers.js:129:24)
    at resolve (/ProjectName/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:33)
    at /ProjectName/node_modules/metro/src/DeltaBundler/traverseDependencies.js:412:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (/ProjectName/node_modules/metro/src/DeltaBundler/traverseDependencies.js:411:33)
    at processModule (/ProjectName/node_modules/metro/src/DeltaBundler/traverseDependencies.js:140:31)
    at async addDependency (/ProjectName/node_modules/metro/src/DeltaBundler/traverseDependencies.js:230:18)
    at async Promise.all (index 6)

如能提供任何帮助,我们将不胜感激!

2个回答

我相信您收到了有关在 React Native 应用上安装 react-native-reanimated 的说明的警告消息,并决定按照 https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation

这是我的情况,在我按照他们要求我做的一切操作后,我开始收到此错误。

以下是我为修复此问题所做的事情:

  1. 首先,我没有按照他们建议的那样安装 react-native-reanimated@next (安装 2.3.0-beta2 ),而是安装了最新的稳定版本, 2.2.3
  2. 然后我测试了一下,问题消失了,但我的应用程序一直冻结。然后我决定撤消他们说明中的另一个步骤,并在 android/app/build.gradle
  3. 中设置 enableHermes: false

这帮我解决了问题。

Sam
2021-10-28

通过执行此命令重置 JavaScript 缓存:

npx react-native start --reset-cache
Pavel Chuchuva
2022-03-05