-
-
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
.env NODE_PATH is not working in v1.0.0 #2230
Comments
Didn't knew you could add that to
I've got a problem with paths in tests by the way but I don't know if that's related to |
This is a real deal-breaker on upgrades to apps that use this form of importing. Changing an entire app to use relative paths will be tiresome. I tried @ingro's suggestion but that didn't work for me; still getting |
Interesting. Anyone looked yet into why this happens? |
Same for me. Have |
Thanks for confirming. Would be good if somebody could take a peek in the source into why. I'd expect it to work. |
Seems unrelated to |
As stated above I have only problems with tests, moving the
If I change imports in tests to be relative the error disappear. This doesn't seem related to |
Can you show the test code? Does it import |
Looks like |
I could've messed it up when refactoring something although I'd expect our E2E tests to catch that. |
I don't believe any of our e2e tests use the |
Sure @gaearon , no // src/__tests__/modules/statistiche/statistiche.test.js
import { actions } from 'modules/statistiche/actions/statistiche';
describe('Statistiche actions', () => {
it('refreshAll action', () => {
expect(actions.refreshAll()).toMatchSnapshot();
});
// ...
}); Also the imported file is pretty basic: // src/modules/statistiche/actions/statistiche.js
const REFRESH_ALL = 'statistiche/REFRESH_ALL';
// ...
function refreshAll() {
return {
type: REFRESH_ALL
};
} |
Thanks @gaearon I'll try to create a repo to show the problem in the afternoon |
I agree with @gaearon, that's the reason. First we include |
Lol. I guess we should just duplicate that resolving code in |
@ingro BTW I fixed my tests with cross-env so it looks like that now |
in webpack config:
the problem that
at least works for me. |
Thanks for the suggestion @RIP21 but still not working for me, I was already running tests like this: "scripts": {
"test:cra": "react-scripts test --env=jsdom",
"test": "cross-env NODE_PATH=./src npm run test:cra"
} |
The issue with Jest is unrelated, and caused by a different change in it. |
Would you consider adding Webpack alias? I really think that I think the idea in Vue webpack template is great: alias: {
'@': resolve('src')
} so you can import Hello from '@/components/Hello' and it's totally optional for users. Anyone who prefer relative paths can simply keep using them and ignore the alias. Of course it doesn't need to be |
No, we don't plan to support non-standard extensions to Node resolution algorithm. This breaks every single tool that can operate on your projects. |
Okay, the fix for Jest is here: jestjs/jest#3616. |
|
Thanks @gaearon , now my tests are running again :D |
Looks like it still not working. In the https://github.com/CodinCat/cra-env-issue exist one Environment
|
@EddiG, I'd like to ask @gaearon |
Please don't override already set variables. We set these on our Jenkins jobs and allow for each job to set up its own environment whilst keeping a .env file in the repo for development. |
@will-stone, I agree but it can be an option for file |
I think in this case the best way to do it is to put |
@FezVrasta do you use react-app-rewired? |
I never got
|
@tamsanh lol. Interesting hack tho :D |
I go in the following way (
|
@yarbshk that requires ejecting. However I agree that using an "@" symbol is nice, and would put the tool on par with Vue; helping users coming from there. |
@tamsanh I really like your approach because I really don't like having to define environment variables everywhere. But I hit an error after defining the package.json as you did, where src/Login/index.js couldnt be resolved when running yarn start. When running eslint, it seemed to assume that every import statement in any file under src was also a package and so threw a ton of errors. Any other details you can provide about how you got your solution working? |
If this is valuable why don’t you file an issue for this? 🙂 Maintainers almost never read closed issues because there is too much noise. If feature requests happen in closed issues we won’t see your feature requests. I’ll lock this issue because it is going off-topic. You are welcome to file more specific issues with your problems and suggestions, but using an old bug for a completely unrelated discussion just serves to confuse future readers coming here from Google etc. Thanks! |
Description
I have
NODE_PATH=src
in.env
, it did work great in v0.9.5. Afteryarn upgrade react-scripts
it doesn't work now. And I didn't see any related guide in the v1.0.0 changelog.(referenced from #2188)
I've also tried in a fresh new project and it doesn't work.
Expected behavior
Should be able to
import 'foo/bar'
whichfoo
is a folder located insrc
Actual behavior
Module not found: Can't resolve 'foo/bar' in '/Users/some/path/src'
Environment
Run these commands in the project folder and fill in their results:
npm ls react-scripts
(if you haven’t ejected):v1.0.0
node -v
:v7.1.0
npm -v
:v3.10.9
Then, specify:
macOS Sierra
Chrome 58
Reproducible Demo
https://github.com/CodinCat/cra-env-issue
This is a fresh new project. See
/src/index.js:5
The text was updated successfully, but these errors were encountered: