Can't use NODE_PATH with two directories
See original GitHub issueIs this a bug report?
Yes
Can you also reproduce the problem with npm 4.x?
Did not try
Which terms did you search for in User Guide?
NODE_PATH, indexOf, undefined
Environment
node -v
: v8.7.0npm -v
: 5.6.0yarn --version
(if you use Yarn):npm ls react-scripts
(if you haven’t ejected):
Then, specify:
- Operating system: MacOS
- Browser and version (if relevant): N/A
Steps to Reproduce
(Write your steps here:)
- Create a
.env
file in the root folder. Add NODE_PATH to it containing two directories:NODE_PATH=src:../shared
- Run
npm start
. You will get the following error:
/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/react-dev-utils/ModuleScopePlugin.js:28
request.descriptionFileRoot.indexOf('/node_modules/') !== -1 ||
^
TypeError: Cannot read property 'indexOf' of undefined
at Resolver.resolver.plugin (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/react-dev-utils/ModuleScopePlugin.js:28:37)
at Resolver.applyPluginsAsyncSeriesBailResult1 (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/tapable/lib/Tapable.js:256:13)
at runNormal (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/Resolver.js:130:20)
at Resolver.doResolve (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/Resolver.js:116:3)
at Resolver.<anonymous> (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/TryNextPlugin.js:16:12)
at Resolver.applyPluginsAsyncSeriesBailResult1 (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/tapable/lib/Tapable.js:256:13)
at runNormal (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/Resolver.js:130:20)
at Resolver.doResolve (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/Resolver.js:116:3)
at Resolver.<anonymous> (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/FileKindPlugin.js:17:12)
at Resolver.applyPluginsAsyncSeriesBailResult1 (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/tapable/lib/Tapable.js:256:13)
at runNormal (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/Resolver.js:130:20)
at Resolver.doResolve (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/Resolver.js:116:3)
at Resolver.<anonymous> (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/NextPlugin.js:14:12)
at Resolver.applyPluginsAsyncSeriesBailResult1 (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/tapable/lib/Tapable.js:256:13)
at runAfter (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/Resolver.js:152:20)
at innerCallback (/Users/nbhati/projects/myapp-monorepo/myapp-embeds/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
Expected Behavior
App is able to build correctly using packages from src
and ../shared
Actual Behavior
Build crashes with TypeError: Cannot read property 'indexOf' of undefined
Reproducible Demo
None
Issue Analytics
- State:
- Created 6 years ago
- Comments:28 (4 by maintainers)
Top Results From Across the Web
How to go back 1 folder level with __dirname? - Stack Overflow
Here is the code i am using and i cannot seems to go 1 level back in the folder directory . When i...
Read more >Gradle fails with Cannot run program "node" (in directory ...
Cannot run program "node" (in directory "/home/luizmarques/Development/sexyfit-app/android"): error=2, No such file or directory * Try: Run ...
Read more >Working with file system paths and file URLs on Node.js - 2ality
Each drive has a current directory. There is a current drive. We can use path.chdir() to set both at the same time:
Read more >How To Use __dirname in Node.js - DigitalOcean
Step 2 — Using __dirname ... You can use __dirname to check on which directories your files live. ... Then, run the script:...
Read more >Python - node.path() - In documentation | Forums - SideFX
I happened to come across a reference of using node.path()and this was a part that I needed to make what I want work....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@razum2um, I finally solved my code sharing issue using yarn-workspaces. You can read about my solution here: Sharing UI Components with Lerna and Yarn Workspaces.
NODE_PATH
exists for absolute imports, some people will dosrc/components/
andsrc/containers/
and make sure there are unique names