Skip to content

Commit 5301d3f

Browse files
authored
fix(examples): allow project node_modules to be used (#2200)
## Description The custom resolver implemented in our `metro.config.js` right now most likely does not conver all cases. When working on my PR with modals for Android I've added `jotai` package and received errors from bundler that this package is not found, because: 1. it was not present in any nearby `node_modules` - the file that requries it resides now in `apps/test-examples`, thus application `node_modules` are not checked by default, 2. only our custom resolver looks into apps `node_modules` & fails to resolve this package. I haven't investigated why it does not work for `jotai` in particular, because more general solution is to just let the default module resolution algorithm look into application `node_modules` as it should always do. ## Changes Added application `node_modules` to the list of additional node modules in metro config of each example application. ## Test code and steps to reproduce Install `jotai` w/o this change, require it in any example and try to run the application. Then apply changes from this PR and see it works well. ## Checklist - [ ] Ensured that CI passes
1 parent a955764 commit 5301d3f

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

Example/metro.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const modules = [
2222

2323
const resolvedExts = ['.ts', '.tsx', '.js', '.jsx'];
2424

25+
const projectNodeModules = path.join(__dirname, 'node_modules');
26+
2527
const config = {
2628
projectRoot: __dirname,
2729
watchFolders: [rnsRoot],
@@ -42,7 +44,7 @@ const config = {
4244
return acc;
4345
}, {}),
4446

45-
nodeModulesPaths: [path.join(__dirname, '../../')],
47+
nodeModulesPaths: [projectNodeModules, path.join(__dirname, '../../')],
4648

4749
// Since we use react-navigation as submodule it comes with it's own node_modules. While loading
4850
// react-navigation code, due to how module resolution algorithms works it seems that its node_modules

FabricExample/metro.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const modules = [
2222

2323
const resolvedExts = ['.ts', '.tsx', '.js', '.jsx'];
2424

25+
const projectNodeModules = path.join(__dirname, 'node_modules');
26+
2527
const config = {
2628
projectRoot: __dirname,
2729
watchFolders: [rnsRoot],
@@ -41,7 +43,7 @@ const config = {
4143
return acc;
4244
}, {}),
4345

44-
nodeModulesPaths: [path.join(__dirname, '../../')],
46+
nodeModulesPaths: [projectNodeModules, path.join(__dirname, '../../')],
4547

4648
// Since we use react-navigation as submodule it comes with it's own node_modules. While loading
4749
// react-navigation code, due to how module resolution algorithms works it seems that its node_modules

FabricTestExample/metro.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const modules = [
2222

2323
const resolvedExts = ['.ts', '.tsx', '.js', '.jsx'];
2424

25+
const projectNodeModules = path.join(__dirname, 'node_modules');
26+
2527
const config = {
2628
projectRoot: __dirname,
2729
watchFolders: [rnsRoot],
@@ -41,7 +43,7 @@ const config = {
4143
return acc;
4244
}, {}),
4345

44-
nodeModulesPaths: [path.join(__dirname, '../../')],
46+
nodeModulesPaths: [projectNodeModules, path.join(__dirname, '../../')],
4547

4648
// Since we use react-navigation as submodule it comes with it's own node_modules. While loading
4749
// react-navigation code, due to how module resolution algorithms works it seems that its node_modules

TVOSExample/metro.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const modules = [
2222

2323
const resolvedExts = ['.ts', '.tsx', '.js', '.jsx'];
2424

25+
const projectNodeModules = path.join(__dirname, 'node_modules');
26+
2527
const config = {
2628
projectRoot: __dirname,
2729
watchFolders: [rnsRoot],
@@ -42,7 +44,7 @@ const config = {
4244
return acc;
4345
}, {}),
4446

45-
nodeModulesPaths: [path.join(__dirname, '../../')],
47+
nodeModulesPaths: [projectNodeModules, path.join(__dirname, '../../')],
4648

4749
// Since we use react-navigation as submodule it comes with it's own node_modules. While loading
4850
// react-navigation code, due to how module resolution algorithms works it seems that its node_modules

TestsExample/metro.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const modules = [
2222

2323
const resolvedExts = ['.ts', '.tsx', '.js', '.jsx'];
2424

25+
const projectNodeModules = path.join(__dirname, 'node_modules');
26+
2527
const config = {
2628
projectRoot: __dirname,
2729
watchFolders: [rnsRoot],
@@ -41,7 +43,7 @@ const config = {
4143
return acc;
4244
}, {}),
4345

44-
nodeModulesPaths: [path.join(__dirname, '../../')],
46+
nodeModulesPaths: [projectNodeModules, path.join(__dirname, '../../')],
4547

4648
// Since we use react-navigation as submodule it comes with it's own node_modules. While loading
4749
// react-navigation code, due to how module resolution algorithms works it seems that its node_modules

0 commit comments

Comments
 (0)