When using expo-liquid-glass-view in a monorepo or a workspace where the package source is located in a parent directory, you must configure metro.config.js to prevent duplicate module instances and dependency conflicts.
Key requirements:
- Exclude parent
node_modules: Use config.resolver.blockList to prevent Metro from bundling react and react-native from the root node_modules, which avoids version mismatches. - Exclude build artifacts: If the root contains both
src and build folders, add the build directory to the blockList to prevent "Tried to register two views with the same name" errors caused by duplicate native view registrations. - Set
nodeModulesPaths: Include both the local node_modules and the root node_modules to ensure the resolver finds necessary dependencies. - Map
extraNodeModules: Explicitly map the package name expo-liquid-glass-view to its source directory to ensure imports resolve correctly to the source code rather than a compiled version. - Add
watchFolders: Include the project root in config.watchFolders so Metro tracks changes in the source directory.
const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");
const config = getDefaultConfig(__dirname);
const root = path.resolve(__dirname, "..");
config.resolver.blockList = [
...Array.from(config.resolver.blockList ?? []),
new RegExp(path.resolve(root, "node_modules", "react").replace(/\\/g, "\\\\")),
new RegExp(path.resolve(root, "node_modules", "react-native").replace(/\\/g, "\\\\")),
new RegExp(`^${path.resolve(root, "build").replace(/\\/g, "\\\\")}/.*$`),
];
config.resolver.nodeModulesPaths = [
path.resolve(__dirname, "./node_modules"),
path.resolve(root, "node_modules"),
];
config.resolver.extraNodeModules = {
"expo-liquid-glass-view": path.resolve(root, "src"),
};
config.watchFolders = [root];
module.exports = config;