-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Absolute path guide #1712
Absolute path guide #1712
Conversation
Guide to add absolute path configuration.
@@ -346,6 +346,35 @@ Learn more about ES6 modules: | |||
* [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html) | |||
* [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules) | |||
|
|||
## Importing a Component using path relative to src (Absolute path) | |||
|
|||
Create a file called `.env` in the root of the project, then add the following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.env is exists in .gitignore
. So anyone that is collaborating will not have the file and need to do this in the project. I think this setting should not exists in .env
. Can we tell them to install cross-env and do cross-env NODE_PATH=./src react-scripts start
in .scripts in package.json instead?
@gaearon can we make the NODE_PATH configurable in package.json? 😄 So the user can just set it once and be done with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there was an argument posted somewhere on these issues arguing to check .env into source control, as it doesn't contain any secrets (client side code shouldn't).
I don't believe we're going to add new configuration for this, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but i believe that .env should contain the environment specific setting like CHOKIDAR_USE_POLLING
which doesn't need to turned on in specific env. This env variable is making the codes in src
directly dependent to have it setup.
So, this would cause confusion if the docs says it like this right now. For example, when the original author push it to a git repo and other team member tries to clone it, the repo is not working in other team member local machine because of the missing .env files. And we have "it's working on my local machine" problem all over again.
I think right now If we want to document NODE_PATH
in the docs we need to use the cross-env in the scripts, or make it configurable.
The officially supported ways of making an absolute import is discussed here #1065 so I think that this pr would be better to document that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there was an argument posted somewhere on these issues arguing to check .env into source control, as it doesn't contain any secrets (client side code shouldn't).
Yes, we'll remove it from gitignore as part of #1344.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok then, I'm not aware of this. Just experienced an "it's working on my local machine" because of .env
that's is missing. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why not it doesn't work when I use 'npm start ' to run my project ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall that Rails' dotenv (which takes care of loading this .env
file in a rails app environment) was able to recognize several .env
files, like .env
, .env.local
, .env.development
, .env.production
, etc. I think this would fix this issue. The settings to be checked into source control live in .env
, where a comment can specify that any other settings needed only by a specific developer in their local environment should be set in the .env.local
file instead.
Derp... I totally forgot about this PR. |
Eh. I feel like we should just figure out fixes necessary for #1333 instead of promoting this approach. Thanks for PR though! |
Guide to add absolute path configuration, according to the last comment from #741