Open polcats opened 1 year ago
@polcats I was able to solve this by adding a custom resolver to metro.config.js:
const blacklistedModules = [
'fs',
'http',
'https',
'net',
'tls',
'child_process',
'cluster',
'path',
'stream',
'tty',
'zlib',
];
module.exports = {
...config,
...your_settings_here,
resolver: {
...resolver,
...your_settings_here,
resolveRequest: (context, moduleName, platform) => {
if (blacklistedModules.includes(moduleName)) {
return {
type: 'empty',
};
}
return context.resolveRequest(context, moduleName, platform);
},
},
};
Expected Behavior
Importing
contentful
library in a react-native app works without errorsActual Behavior
Contentful is trying to import a Node functionality:
Possible Solution
Find a workaround to avoid
fs
?Steps to Reproduce
Context
We are working on a monorepo project that uses NextJS and react-native. The contentful library is already getting used in the NextJS app. The ideal situation is that we can also use the library in react-native with minimal changes.
Environment