react-native - 使用带有 React 本机 init 的 yarn 工作区时缺少依赖项
问题描述
我想设置一个monorepo。我将我的 React 本机项目npx react-native init myProject
作为第一个项目进行初始化。(后面会有更多项目添加)
文件夹结构
- 家长
- 我的项目
- package.json(由 react-native 创建)
- 纱线锁
- package.json(我设置工作区的地方)
- 我的项目
然后我从 myProject 的父文件夹设置 yarn 工作区。
{ "name": "Parent",
"private": true,
"workspaces": {
"packages": [
"*"
],
"nohoist": [
"**/react-native",
"**/react-native-*",
"**/@react-native-*",
"**/@react-native-*/**",
"**/@react-navigation",
"**/@react-navigation/**",
"**/hermes-engine",
"**/rn-*"
] }
}
一切似乎都有效,直到我推送到 git 并克隆回来。我使用yarn install
但在启动项目时出现此错误(运行 android 或运行 ios)
Error: Unable to resolve module `scheduler` from `node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js`: scheduler could not be found within the project or in these directories:
..\node_modules
我可以解决的唯一方法是 cd myProject 并运行npm install
(它会添加一些包并且应用程序将工作)而 cd 和 usingyarn install
不会做任何事情
我只想在项目中使用纱线,那么我该怎么做才能解决这个问题?
解决方案
我想办法解决它。我忘了编辑 RN 文件夹中的 metro.config。
const path = require('path')
const linkedLibs = [path.resolve(__dirname, '..')]
console.info('CONFIG', linkedLibs)
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
watchFolders: linkedLibs,
};
使用它,一切都会好起来的
推荐阅读
- c# - IBMMQDotnetClient 使用 Windows 凭证而不是应用程序指定的凭证
- regex - 我正在寻找一个不允许连续超过星号的正则表达式
- android - Android:尽管有读/写权限,但无法列出文件
- jenkins - pmd 插件在 jenkins 中不可用
- java - 如何在 Java 中替换正则表达式命名捕获组的内容
- c - 忽略:我只是重命名了标题来尝试一下
- python - 为什么通过python中的过滤器时文件听起来很糟糕
- java - 如何存储和检索泛型类型
- spring-boot - org.hibernate.QueryException:在 [] 之前未索引 fromElement
- regex - 如何使用正则表达式替换子字符串中的特定字符?