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

作者站长头像
站长
· 阅读数 23

我在项目的根目录执行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',请问有哪位大神,遇到了,亟待解决,求帮助?如果提供的思路能够解决问题,会给予一个红包作为回报。

回复
1个回答
avatar
test
2024-07-02

已经找到解决办法。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
      },
    },
  }
}
回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容