如何在没有 npm 的情况下手动从 github 下载和导入 node 模块,并将其安装在 React Native 项目中?

Posted

技术标签:

【中文标题】如何在没有 npm 的情况下手动从 github 下载和导入 node 模块,并将其安装在 React Native 项目中?【英文标题】:How to download and import node modules from github manually without npm, and install it in the React Native project? 【发布时间】:2020-11-11 18:06:14 【问题描述】:

在我的项目中,我们使用react-native-azure-ad 插件。问题是,npm 上的这个插件已经过时,并且使用了一种不推荐的方式来访问已经从 react-native 提取到 react-native-webview 的 webview。

当我浏览github page并观察那里的源代码时,似乎github上的代码已经更新为使用react-native-webview,这让我相信npm包没有被更新作者关注github版本。

只有一种方法可以解决这个问题,即直接从 github 下载模块并手动导入。问题是,我只知道如何通过 npm 安装导入模块。

目前,这是基本的文件夹结构:

Root
- node_modules  
- src  --> the app source code

我想把模块这样放:

Root
- node_modules
- node_updates
  - react-native-azure-ad
- src

而且我希望仍然能够像这样导入它:

import ReactNativeAD, ADLoginView from 'react-native-azure-ad'

当然,我会从 package.json 中删除 react-native-azure-ad,然后重新安装 node_modules。

这可能吗?

我希望我不必依赖相对路径,例如:

import ReactNativeAD, ADLoginView from '../../../node_updates/react-native-azure-ad'

我看过一些类似this的答案,但这需要我使用相对路径来导入。

【问题讨论】:

【参考方案1】:

使用npm:

npm install <git-host>:<git-user>/<repo-name>

npm install <git repo url>

当使用公共 git repo 时。

使用yarn:

yarn add <git remote url>

yarn add &lt;git remote url&gt;#&lt;branch/commit/tag&gt; 当您需要特定分支等时。

【讨论】:

以上是关于如何在没有 npm 的情况下手动从 github 下载和导入 node 模块,并将其安装在 React Native 项目中?的主要内容,如果未能解决你的问题,请参考以下文章