This repository was archived by the owner on Mar 17, 2025. It is now read-only.
This repository was archived by the owner on Mar 17, 2025. It is now read-only.
expo-router + custom metro.config.js (resolveRequest
) #501
Closed
Description
Summary
It seems that expo-router
overrides resolveRequest
in metro.config.js
, which is needed for some packages (in my case it's graphql-request
I confirmed that without expo-router
this works as expected, but after configuring expo-router
, I keep getting Unable to resolve "graphql-request" from "index.js"
. Something is going on with how metro.config is resolved, but I can't pin point where
Minimal reproducible example
metro.config.js
I tried 2 different ways
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);
config.resolver = {
...config.resolver,
resolveRequest: (context, moduleName, platform) => {
if (moduleName.startsWith('graphql-request')) {
return {
filePath: `${__dirname}/node_modules/graphql-request/build/esm/index.js`,
type: 'sourceFile',
}
}
return context.resolveRequest(context, moduleName, platform)
}
}
module.exports = config
module.exports = (async () => {
const config = await getDefaultConfig(__dirname);
const { resolver } = config;
config.resolver = {
...resolver,
resolveRequest: (context, moduleName, platform) => {
console.log('resolveRequest', moduleName)
if (moduleName.startsWith('graphql-request')) {
return {
filePath: `${__dirname}/node_modules/graphql-request/build/esm/index.js`,
type: 'sourceFile',
}
}
return context.resolveRequest(context, moduleName, platform)
}
};
return config;
})();
index.js
(or any other file where something is imported from graphql-request
)
// import this just as an example
import { request, gql } from 'graphql-request'
import "expo-router/entry";