monorepo: expo with yarn workspace and using expo install

╄→гoц情女王★ 提交于 2020-04-16 05:47:10

问题


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.

回答1:


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

then i ran npm install to install all my dependencies. now its time to install expo-yarn-workspace with npm install --save-dev expo-yarn-workspaces. 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.ts",

run npm run postinstall

then you can start your app with npm start --clear to clear the cache

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

also checkout this guide if you care.

Hope it solves your problem.



来源:https://stackoverflow.com/questions/59920012/monorepo-expo-with-yarn-workspace-and-using-expo-install

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!