问题
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