| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
Sorry, something went wrong.
| }, { | ||
| 'process.env.NODE_ENV': NODE_ENV | ||
| 'process.env.NODE_ENV': NODE_ENV, | ||
| 'process.env.NODE_PATH': NODE_PATH |
There was a problem hiding this comment.
env.js is only used for variables injected into the app.
Doesn't seem like it's useful to expose it to the path.
Sorry, something went wrong.
env.js is only for variables injected into the app.
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Sorry, something went wrong.
Definitely, we want to have feature parity with how Browserify treats NODE_PATH (which is likely how Node treats it, but would be great if you could check the source). |
Sorry, something went wrong.
|
I couldn't find exactly where browserify handles NODE_PATH, but this test seems to suggest they support NODE_PATH the way node does. I've added support for multiple paths. I moved the logic to paths.js. I'm not sure if this is the right place, but it seemed to make the most sense so that I don't duplicate the logic in the prod and dev config. I have not tested this on windows myself, but I did test on my mac that local paths resolve when build and testing. |
Sorry, something went wrong.
|
Glad to see this added to a milestone! Any changes that need to before made before it could be merged? |
Sorry, something went wrong.
|
Can you please verify that newly added testing with Jest also works? |
Sorry, something went wrong.
|
Out in 0.4.0. Thanks again! |
Sorry, something went wrong.
|
It is really confusing here how to use this feature. Could someone give an example of exactly what you need to enter into your command line to make the sample App run with this line: Tried a lot of variations of things like: |
Sorry, something went wrong.
|
@mandysimon88 If you use Bash on OS X or Linux, this should work: NODE_PATH=./src npm start
NODE_PATH=./src npm run build
NODE_PATH=./src npm testIf you use Cmd on Windows: NODE_PATH=./src&&npm start
NODE_PATH=./src&&npm run build
NODE_PATH=./src&&npm testNote that lack of whitespace on Windows is intentional. Does this help? |
Sorry, something went wrong.
|
(I understand it’s frustrating this feature isn’t documented. It was added as a stopgap measure so we’d prefer not to advertise it widely. Ideally we’ll figure out some different solution to this before 1.0.) |
Sorry, something went wrong.
|
Yes, this was really helpful. We ended up trying about 20 different variants on NODE_PATH= ? before stumbling on the answer. I can understand your desire not to advertise widely, but seriously, relative paths are a pain… I’m bringing over 33k lines of code from a previous project based on angular, and faced with updating the paths of every single import in every file. You can imagine the task.
|
Sorry, something went wrong.
|
Oh I can imagine. :P |
Sorry, something went wrong.
There's been numerous requests for Create-React-App to support having imports resolved relative to the "src" folder. The semi-documented solution is to have a NODE_PATH environment variable, which will be used in the resolution process. It's apparently also possible to specify that variable in a file named ".env". References: react/create-react-app#476 react/create-react-app#693 react/create-react-app#741
There's been numerous requests for Create-React-App to support having imports resolved relative to the "src" folder. The semi-documented solution is to have a NODE_PATH environment variable, which will be used in the resolution process. It's apparently also possible to specify that variable in a file named ".env". References: react/create-react-app#476 react/create-react-app#693 react/create-react-app#741
|
When I run NODE_PATH=./src npm start import App from './components/App'; works import App from 'src/components/App'; doesn't work Am I missing something? |
Sorry, something went wrong.
|
In order to make that import you would need to have NODE_PATH=. npm start. I personally recommend putting this in your package.json. "start": "NODE_PATH=. react-scripts start", |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This addresses #253. Nothing should change by default, but you are able to set your NODE_PATH environment variable if you want absolute path imports.
Test Plan
I tested this by changing import App from './App'; to import App from 'App'; in index.js. Without setting NODE_PATH run and build will now fail because it can't find the module. After setting the the NODE_PATH to `./template/src' the project both builds and runs.
I also generated a new project, which you can find here that uses this absolute import. I did the equivalent change in the tests directory and the tests pass.
Let me know if you have any questions or any suggestions.