أخطاء APK

Metro: Unable to resolve module

نص الخطأ

error: Error: Unable to resolve module ./components/Header from /app/src/App.js:
None of these files exist: * components/Header(.native|.android.ts|.ts|.js|.json)

السبب

لا يجد Metro bundler الملف أو الحزمة المستوردة. قد يكون السبب اسمًا أو مسارًا خاطئًا أو حالة الأحرف أو تثبيتًا ناقصًا.

الحل خطوة بخطوة

  1. قارن المسار في الخطأ باسم الملف الحقيقي؛ Header تختلف عن header.
  2. شغّل npm install للحزم وتأكد أنها في package.json.
  3. صفّر الذاكرة المؤقتة بـ npx expo start --clear.
  4. احذف node_modules وثبّت من جديد.
  5. في monorepo افحص watchFolders في metro.config.js.

أوامر للمثال

npx expo start --clear
npx react-native start --reset-cache
rm -rf node_modules && npm install
watchman watch-del-all

كيف لا يتكرر

سمِّ الملفات بنمط أحرف موحد؛ فالفرق مهم في Linux.

المؤلف والترخيص: Nibras Code