I'm trying to run expo on a turborepo.
Running pnpm dev
gives me the following error:
Unable to resolve "expo" from "index.ts"
And the simulator the following screen with the following error:
Unable to resolve module expo from /Users/xx/main/apps/expo/index.ts: expo could not be found within the project or in these directories:
node_modules
../../node_modules
> 1 | import { registerRootComponent } from "expo";
| ^
2 |
3 | import { App } from "./src/_app";
4 |
I have tried to delete all my node_modules
. I have tried to clean my entire project. I have no idea what to do next.
Here is my metro.config.js
:
// Learn more: https://docs.expo.dev/guides/monorepos/
const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");
const projectRoot = __dirname;
const workspaceRoot = path.resolve(projectRoot, "../..");
// Create the default Metro config
const config = getDefaultConfig(projectRoot);
// Add the additional `cjs` extension to the resolver
config.resolver.sourceExts.push("cjs");
// 1. Watch all files within the monorepo
config.watchFolders = [workspaceRoot];
// 2. Let Metro know where to resolve packages and in what order
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, "node_modules"),
path.resolve(workspaceRoot, "node_modules"),
];
// 3. Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
config.resolver.disableHierarchicalLookup = true;
module.exports = config;
Here is my package.json
:
{
"name": "@acme/expo",
"version": "0.1.0",
"main": "index.ts",
"scripts": {
"clean": "rm -rf .expo .turbo node_modules",
"dev": "expo start --ios",
"dev:android": "expo start --android",
"dev:ios": "expo start --ios",
"lint": "eslint",
"type-check": "tsc --noEmit"
},
"dependencies": {
"expo": "~47.0.12",
"expo-status-bar": "~1.4.2",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5",
"react-native-safe-area-context": "4.4.1",
"expo-splash-screen": "~0.17.5"
},
"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"@babel/runtime": "^7.19.0",
"@expo/config-plugins": "^5.0.4",
"@types/react": "^18.0.25",
"@types/react-native": "~0.70.8",
"eslint": "^8.30.0",
"typescript": "^4.9.4"
},
"private": true
}
Thanks you for helping.
I couldn't get it working with pnpm (I tried for way too long), so I switched over to yarn 1 (classic) workspaces and it worked. Yarn 1 workspaces are the only workspace solution that Expo supports, so I recommend going with that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.