You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native链接第三方库失败,报错Cannot read property '_text' of undefined

Fixing "ERRPACKAGEJSON No package found" When Linking React Native Libraries

Hey there, let's work through this linking error you're hitting with react-native-fetch-blob (and all other third-party libraries, it seems). The error message you're seeing—ERRPACKAGEJSON No package found. Are you sure this is a React Native project? Cannot read property '_text' of undefined—usually points to issues with your project structure, package.json integrity, or tooling state. Here are step-by-step fixes to try:

1. Double-check you're in the right directory

First off, make sure you're running the react-native link command from the root directory of your React Native project. This is the folder that contains your package.json file. To confirm:

  • On Mac/Linux: Run pwd and verify the path matches your project's root.
  • On Windows: Run cd to see your current directory.

If you're in a subfolder (like android/ or ios/), switch back to the root with cd .. as needed, then re-run the link command.

2. Verify your package.json exists and is valid

  • Check if package.json is present in your project root. If it's missing, you might not be in a React Native project, or the file was accidentally deleted.
  • If the file exists, check for syntax errors (like missing commas, mismatched brackets). You can validate it quickly with:
    npm validate
    
    Fix any errors it flags, then try linking again.

3. Clean dependencies and npm cache

Corrupted node_modules or cached data often cause these kinds of issues. Let's reset your dependency state:

  • Delete the node_modules folder:
    # Mac/Linux
    rm -rf node_modules
    
    # Windows (Command Prompt)
    rd /s /q node_modules
    
  • Clear the npm cache:
    npm cache clean --force
    
  • Reinstall all dependencies:
    npm install
    
  • Now try linking again:
    react-native link react-native-fetch-blob
    

4. Update your React Native CLI (or use npx)

Older versions of the React Native CLI might have compatibility bugs. Try either:

  • Update the global CLI:
    npm install -g react-native-cli
    
  • Or use npx to run the latest CLI version without global installation:
    npx react-native link react-native-fetch-blob
    

5. Fall back to manual linking

If automatic linking still fails, you can link react-native-fetch-blob manually for each platform:

For iOS

  1. Open your Xcode project (.xcworkspace file) in the ios/ folder.
  2. Drag node_modules/react-native-fetch-blob/ios/RNFetchBlob.xcodeproj into the Libraries group of your project.
  3. Go to your target's Build Phases > Link Binary With Libraries, then click the + button and add libRNFetchBlob.a.

For Android

  1. Open android/settings.gradle and add these lines:
    include ':react-native-fetch-blob'
    project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android')
    
  2. Open android/app/build.gradle and add this line to the dependencies block:
    implementation project(':react-native-fetch-blob')
    
  3. Open android/app/src/main/java/[your-package-name]/MainApplication.java:
    • Add the import: import com.RNFetchBlob.RNFetchBlobPackage;
    • In the getPackages() method, add new RNFetchBlobPackage() to the returned list.

6. Confirm your project is a valid React Native project

Last check: Make sure your project has the standard React Native structure—you should see android/, ios/, index.js (or App.js), and of course package.json in the root. If any of these are missing, you might be working in a non-RN project directory.


内容的提问来源于stack exchange,提问作者Ravi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:33:50