metro
metro copied to clipboard
"resolver.extraNodeModules" config doesn't work without "watchFolders"
Do you want to request a feature or report a bug?
Bug and feature request
What is the current behavior?
If you want resolver.extraNodeModules to work, you need to add the whole extra modules directory to watchFolders list. In big projects with a lot of shared libraries it causes a bug crashing iOS Simulator opening, if your MacBook is not Pro with 16 Gb RAM.
Error: EMFILE: too many open files, watch at FSEvent.FSWatcher._handle.onchange
What is the expected behavior?
In our project each shared library is a TypeScript projects. We start TS compilation in watch mode for all libraries in parallel with react-native run-ios
. Each library has its own .tsbuildinfo
file, pointing if the library code was updated or not. We want to add to Metro watchFolders not the whole library directory, but only its .tsbuildinfo
. Whenever .tsbuildinfo
changes, iOS Simulator will reload.
Unfortunately, configuring metro.config.js
like this doesn't work, resulting an error "Can't resolve module ..." from shared library.
It seems that resolver.extraNodeModules requires parent path to be part of watchFolders. We want to make this optional.
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
const path = require('path')
const extraNodeModules = {
'ui-kit': path.resolve(__dirname, '../shared/ui-kit/dist')
}
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
resolver: {
extraNodeModules: new Proxy(extraNodeModules, {
get: (target, name) => {
if (name === 'ui-kit') {
return target[name]
}
return path.join(process.cwd(), `node_modules/${name}`)
},
}),
},
watchFolders: [
path.resolve(__dirname, '../shared/ui-kit/tsbuildinfo')
],
}
Note: We have not the latest version of metro
and react-native
"react-native": "0.63.4",
"metro": "0.58",
We are in process of migrating to upcoming RN 0.69.0. Please tell us if this case could be fixed by upgrading to latest RN and Metro?
ping @pieterv
ping ping @pieterv
Have you looked into similar issue already solved like this one? https://github.com/facebook/metro/issues/668#issuecomment-845119616
Thank you for your help @cortinico !! We will test it on Monday and let you know how it works.