Skip to content

Commit 512ccc1

Browse files
gaearonGeorge Czabania
authored and
George Czabania
committed
Tweak how NODE_PATH is handled
1 parent 9bc8908 commit 512ccc1

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

config/paths.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
var path = require('path');
1313

14-
// We support resolving modules according to NODE_PATH.
14+
// We support resolving modules according to `NODE_PATH`.
1515
// This lets you use absolute paths in imports inside large monorepos:
1616
// https://github.com/facebookincubator/create-react-app/issues/253.
17-
// It works just like NODE_PATH in Node:
17+
18+
// It works similar to `NODE_PATH` in Node itself:
1819
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
20+
1921
// We will export `nodePaths` as an array of absolute paths.
20-
// It will then be used by Webpack (and potentially other tools).
22+
// It will then be used by Webpack configs.
23+
// Jest doesn’t need this because it already handles `NODE_PATH` out of the box.
24+
2125
var nodePaths = (process.env.NODE_PATH || '')
2226
.split(process.platform === 'win32' ? ';' : ':')
2327
.filter(Boolean)

config/webpack.config.dev.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ module.exports = {
6868
publicPath: '/'
6969
},
7070
resolve: {
71-
// This allows you to set a root for where Webpack should look for modules.
72-
// It must be an absolute path or an array of absolute paths.
73-
// This lets you use absolute paths in imports inside large monorepos:
74-
// https://github.com/facebookincubator/create-react-app/issues/253.
75-
root: paths.nodePaths,
71+
// This allows you to set a fallback for where Webpack should look for modules.
72+
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
73+
// We use `fallback` instead of `root` because we want `node_modules` to "win"
74+
// if there any conflicts. This matches Node resolution mechanism.
75+
// https://github.com/facebookincubator/create-react-app/issues/253
76+
fallback: paths.nodePaths,
7677
// These are the reasonable defaults supported by the Node ecosystem.
7778
extensions: ['.js', '.json', ''],
7879
alias: {

config/webpack.config.prod.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ module.exports = {
6363
publicPath: publicPath
6464
},
6565
resolve: {
66-
// This allows you to set a root for where Webpack should look for modules.
67-
// It must be an absolute path or an array of absolute paths.
68-
// This lets you use absolute paths in imports inside large monorepos:
69-
// https://github.com/facebookincubator/create-react-app/issues/253.
70-
root: paths.nodePaths,
66+
// This allows you to set a fallback for where Webpack should look for modules.
67+
// We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
68+
// We use `fallback` instead of `root` because we want `node_modules` to "win"
69+
// if there any conflicts. This matches Node resolution mechanism.
70+
// https://github.com/facebookincubator/create-react-app/issues/253
71+
fallback: paths.nodePaths,
7172
// These are the reasonable defaults supported by the Node ecosystem.
7273
extensions: ['.js', '.json', ''],
7374
alias: {

0 commit comments

Comments
 (0)