monorepo:带有纱线工作空间的博览会并使用博览会安装 [英] monorepo: expo with yarn workspace and using expo install
问题描述
我正在尝试设置一个 React 和 Expo monorepo 项目,一切似乎都很好,直到我想根据 react-navigation 使用 expo install
安装 react-navigation
docs,因为 expo install 在后台使用 yarn 并且因为它是工作空间环境,所以会弹出此错误,我不知道如何绕过.有什么想法吗?
纱线添加 v1.21.1info 访问 https://yarnpkg.com/en/docs/cli/add 以获取有关此命令的文档.错误 运行此命令会将依赖项添加到工作区根目录而不是工作区本身,这可能不是您所希望的想要 - 如果你真的是这个意思,请通过使用 -W 标志(或 --ignore-workspace-root-check)再次运行此命令来使其明确.yarnpkg 以非零代码退出:1在您的环境中设置 EXPO_DEBUG=true 以查看堆栈跟踪.
这就是我如何让它与 expo-yarn-workspaces 一起工作.
在我的全局 package.json 文件中,我添加了以下代码.
{私人":是的,工作区":[包/*"],}
然后我在我的根目录中创建了一个名为 packages 的文件夹.
在我的终端中,我 cd packages 然后我用这个命令创建了一个新的 expo 项目
expo 初始化应用
在 package.json
中定义 name
和 version
属性.
然后我安装了所有依赖项:
npm 安装
或
纱线
现在是时候安装 expo-yarn-workspaces 了
npm install --save-dev expo-yarn-workspaces
或
yarn add expo-yarn-workspaces -D
之后,将此脚本添加到您的 package.json
"scripts": {...,安装后":expo-yarn-workspaces 安装后"},
创建一个文件并将其命名为 metro.config.js并粘贴以下代码
const { createMetroConfiguration } = require("expo-yarn-workspaces");module.exports = createMetroConfiguration(__dirname);
在您的 package.json 中替换/添加这行代码
main":__generated__/AppEntry.js",
运行:
npm 运行后安装
或
yarn postinstall
然后您可以使用以下命令启动您的应用程序以清除缓存:
npm start --clear
或
纱线开始--clear
<块引用>
注意:如果您正在运行 create-react-app 和 react-native 它们大多是相同的版本,因此您必须在两个文件夹中运行 npm install react react-dom 才能能够使用相同的版本.
<块引用>
我的 github 回购
有用的链接:
文章 https://divinehycenth.com/blog/yarn-workspace-monorepo.
Github https://github.com/expo/expo/tree/master/packages/expo-yarn-workspaces
希望它能解决你的问题.
I'm trying to setup a React and Expo monorepo project, everything seems good until I want to install react-navigation
with expo install
according to the react-navigation docs, because expo install use yarn in the background and because it's a workspace environment this error pop out, which I have no idea how to bypass. any ideas?
yarn add v1.21.1
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
error Running this command will add the dependency to the workspace root rather than the workspace itself, which might not be what you
want - if you really meant it, make it explicit by running this command again with the -W flag (or --ignore-workspace-root-check).
yarnpkg exited with non-zero code: 1
Set EXPO_DEBUG=true in your env to view the stack trace.
This is how i got it to work with expo-yarn-workspaces.
In my global package.json file i added the following codes.
{
"private": true,
"workspaces": [
"packages/*"
],
}
then i created a folder in my root directory called packages.
In my terminal i cd packages then i created a new expo project with this command
expo init app
Define the name
and version
properties in package.json
.
then i installed all my dependencies:
npm install
or
yarn
now its time to install expo-yarn-workspaces with
npm install --save-dev expo-yarn-workspaces
or
yarn add expo-yarn-workspaces -D
After that you add this script in your package.json
"scripts": {
...,
"postinstall": "expo-yarn-workspaces postinstall"
},
create a file and name it metro.config.js and paste the following code
const { createMetroConfiguration } = require("expo-yarn-workspaces");
module.exports = createMetroConfiguration(__dirname);
in your package.json replace/add this line of code
"main": "__generated__/AppEntry.js",
Run:
npm run postinstall
or
yarn postinstall
then you can start your app with the following command to clear the cache:
npm start --clear
or
yarn start --clear
NOTE: If you're running create-react-app and react-native they most be of the same version so you have to run npm install react react-dom in both folders to be able to use the same version.
My github repo
Useful links:
Article https://divinehycenth.com/blog/yarn-workspace-monorepo.
Github https://github.com/expo/expo/tree/master/packages/expo-yarn-workspaces
Hope it solves your problem.
这篇关于monorepo:带有纱线工作空间的博览会并使用博览会安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!