我试图建立一个反应,世博monorepo项目,一切似乎都很好,直到我想安装react-navigation与expo install根据反应导航文档,因为世博会安装使用的纱线在后台,因为它是一个工作空间环境这个错误弹出,这我不知道如何绕过。有任何想法吗?
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.
Run Code Online (Sandbox Code Playgroud)
小智 11
这就是我让它与expo-yarn-workspaces 一起工作的方式。
在我的全局package.json文件中,我添加了以下代码。
{
"private": true,
"workspaces": [
"packages/*"
],
}
Run Code Online (Sandbox Code Playgroud)
然后我在我的根目录中创建了一个名为packages的文件夹。
在我的终端中,我cd packages然后我用这个命令创建了一个新的 expo 项目
expo init app
Run Code Online (Sandbox Code Playgroud)
中定义name和version属性package.json。
然后我安装了所有依赖项:
npm install
Run Code Online (Sandbox Code Playgroud)
或者
yarn
Run Code Online (Sandbox Code Playgroud)
现在是时候安装expo-yarn-workspaces了
npm install --save-dev expo-yarn-workspaces
Run Code Online (Sandbox Code Playgroud)
或者
yarn add expo-yarn-workspaces -D
Run Code Online (Sandbox Code Playgroud)
之后,您在package.json 中添加此脚本
expo init app
Run Code Online (Sandbox Code Playgroud)
创建一个文件并将其命名为Metro.config.js 并粘贴以下代码
const { createMetroConfiguration } = require("expo-yarn-workspaces");
module.exports = createMetroConfiguration(__dirname);
Run Code Online (Sandbox Code Playgroud)
在你的package.json 中替换/添加这行代码
"main": "__generated__/AppEntry.js",
Run Code Online (Sandbox Code Playgroud)
跑:
npm run postinstall
Run Code Online (Sandbox Code Playgroud)
或者
yarn postinstall
Run Code Online (Sandbox Code Playgroud)
然后您可以使用以下命令启动您的应用程序以清除缓存:
npm start --clear
Run Code Online (Sandbox Code Playgroud)
或者
yarn start --clear
Run Code Online (Sandbox Code Playgroud)
注意:如果您正在运行 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
希望它能解决你的问题。
| 归档时间: |
|
| 查看次数: |
3165 次 |
| 最近记录: |