react-native unlink react-native-doc-viewer时,报了error: unknown command 'unlink'?

我在项目的根目录执行
yarn ios --simulator 'iPhone 14 Pro'命令时,报了如下的错误:

React Native CLI uses autolinking for native dependencies, but the following modules are linked manually:
  • react-native-doc-viewer (to unlink run: "react-native unlink react-native-doc-viewer")
  • react-native-document-picker (to unlink run: "react-native unlink react-native-document-picker")
  • react-native-fs (to unlink run: "react-native unlink react-native-fs")

This is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink <dependency>" and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.
但是当我按照提示去执行:
react-native unlink react-native-doc-viewer命令时,报了
error: unknown command 'unlink',请问有哪位大神,遇到了,亟待解决,求帮助?
如果提供的思路能够解决问题,会给予一个红包作为回报。

阅读 3k
1 个回答

已经找到解决办法。
1、在项目的根目录下新建一个 react-native.config.js文件。
文件中如下配置:

// react-native.config.js
module.exports = {
  dependencies: {
    'react-native-doc-viewer': {
      platforms: {
        android: null,
        ios: null,
        // add more platform to disable auto-linking for them too
      },
    },
    'react-native-document-picker': {
      platforms: {
        android: null,
        ios: null,
        // add more platform to disable auto-linking for them too
      },
    },
    'react-native-fs': {
      platforms: {
        android: null,
        ios: null,
        // add more platform to disable auto-linking for them too
      },
    },
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题