-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use NODE_PATH with two directories #3676
Comments
AFAIK standard NodeJS (e.g. not installed by tools like According to issue template, you have ejected your application. Could you please show output of // Ensure environment variables are read.
require('../config/env'); |
Hi @miraage, thanks for the quick response.
|
Sorry for wrong question. I meant |
|
Oh wow, my memory failed me! My apologies. I'd heed @miraage's advice and check what the value of |
@nareshbhatia are you using symlinks under the |
Here's the value of
I am not using any symlinks. The project is structured as follows:
|
There is also a line inside
@nareshbhatia could you please try to write |
No change :-(. If it helps, I can try to create a minimal app that reproduces this issue. |
Let's try. |
Ok, on it! |
@miraage, I have created a sample monorepo: https://github.com/nareshbhatia/cra-monorepo. Unfortunately I am not able to reproduce the original problem yet. The current problem is that CRA is not recognizing JSX components in the shared folder - this is even before ejecting. The good news is that it is able to reach components in the shared folder! The README file has further details. If you can help me get past this issue, I can try to reproduce the original issue. |
Correct. Only files under src directory will be processed by Babel. I would seek for an issue by reviewing all post-eject configuration changes. |
@miraage, I ejected the app and made bunch of configuration changes:
This allowed the build to progress a bit further, but now something else is tripping up on
|
@nareshbhatia please, take a look at this plugin and comment above. |
@miraage, I completely removed the Unfortunately, I don't have more time to work on this issue. However, I think it is an important one to solve. I see that number of other people are concerned about it too (e.g. #1492). I hope that the CRA team will give it the priority that it deserves. Thanks again for your help. |
I did a test. Fresh ejected CRA app. Added
Commented
Added
Created a
Added
Updated
Works like a charm: screen Don't forget to update both dev/prod webpack configuration files. |
@miraage, thanks for the help. Your solution works because
I am looking for more separation so that two CRA apps can access shared components:
In this case, you will have to set |
@nareshbhatia you must mimic all actions I've provided. Then you'll have no problems at all. |
@miraage, I should have clarified - I tried all actions suggested by you both ways - once with |
I'm about to extract some common code between 2 CRA's in a monorepo, and have the same issue: I wonder, why CRA supports multiple NODE_PATH, but webpack/babel-loader (at least) processes only IMO described monorepo structure feels very natural, but instead, the current approach forces to have a real private npm package (preprocessed to es5 ofc) => which forces either setup a private registry or check in preprocessed es5 code @Timer, btw, could you tell about #2189, because it's not self-explanatory, why did you do it
@miraage thank you for your efforts to show detailed way after eject in #3676 (comment), still I'd rather not, and given existence of "Alternatives to Ejecting" in readme, others don't want to eject as well ;) p.s. I have no clear vision how this could be solved, but I can imagine some tools discovering their's configuration recursively when building sub-projects, wdyt about this? p.p.s just in case: eslint is working after putting into
|
We don't compile source code outside of |
@Timer thanks for a fast reply, still, why support multiple |
@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. |
|
The react-scripts package provided by Create React App requires a dependency: "eslint": "5.6.0" |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs. |
Is 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:
Steps to Reproduce
(Write your steps here:)
.env
file in the root folder. Add NODE_PATH to it containing two directories:NODE_PATH=src:../shared
npm start
. You will get the following error: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
The text was updated successfully, but these errors were encountered: