bundling failed: Error: Unable to resolve module apptify-lib/lib from react native project path: Module local/lib does not exist in the Haste module map or in these directories:
need to configure projectRoot and watchFolders.
Try,
https://facebook.github.io/metro/docs/en/configuration
https://callstack.com/blog/adding-an-example-app-to-your-react-native-library/
Given:
Install plugin babel-plugin-module-resolver
npm i babel-plugin-module-resolver --save-dev
Add module-resolver plugin to babel config (babel.config.js in my case)
// babel.config.js
module.exports = {
//...
plugins: [
['module-resolver',
{
alias: {
'local-lib-alias-name': '../relative/path/to/local/lib',
},
},
],
],
}
_Note:_ it will change your js module imports to right path
Edit metro config (metro.config.js in my case)
// metro.config.js
const path = require('path')
module.exports = {
// ...
watchFolders: [
path.resolve(__dirname, '../relative/path/to/local/lib'),
],
resolver: {
extraNodeModules: new Proxy(
{},
{
get: (target, name) => {
if (target.hasOwnProperty(name)) {
return target[name]
}
return path.join(process.cwd(), `node_modules/${name}`)
},
},
),
},
}
_Note:_
https://callstack.com/blog/adding-an-example-app-to-your-react-native-library/
Notes: getProvidesModuleNodeModules did not work for me so I used solution from Link 2: added extraNodeModules.
https://github.com/facebook/react-native/issues/21310#issuecomment-540227031
@zmefz you are a life saver, thank you!
It seams that the question was answered. Closing. Feel free to re-open if this isn't the case.
Most helpful comment
Given:
Babel
Install plugin babel-plugin-module-resolver
npm i babel-plugin-module-resolver --save-devAdd module-resolver plugin to babel config (
babel.config.jsin my case)_Note:_ it will change your js module imports to right path
Metro
Edit metro config (
metro.config.jsin my case)_Note:_
Links:
https://callstack.com/blog/adding-an-example-app-to-your-react-native-library/
Notes: getProvidesModuleNodeModules did not work for me so I used solution from Link 2: added extraNodeModules.
https://github.com/facebook/react-native/issues/21310#issuecomment-540227031