-
-
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 Imports #4928
Comments
Where are you seeing this error? in npm start? |
after npm/yarn start, everywhere really... its just not searching the path provided in NODE_PATH |
Can you point me to your code? |
Can confirm this behavior, I created a project with create-react-app about 15 minutes ago and reproduced it. Node v8.11.4 Here's my package.json:
Steps to repro:
Failed to compile. ./src/App.js Just for more context, here's src/components/Button/index.js: import React from 'react'
import PropTypes from 'prop-types'
const Button = ({ text = 'buttonText' }) => {
return (
<div>{text}</div>
)
}
Button.propTypes = {
text: PropTypes.string,
}
export default Button It's worth mentioning that if I change the "start" script in package.json to In other words, passing the env var through the package.json script works, while putting it into the .env file doesn't. This runs counter to the docs, or at least what is mentioned in other issues, so it seems like a bug. |
Hi everyone! If placing |
I have the same issue as others mentioned but NODE_PATH is not set on my system yet. The import is resolved successfully but it appears the babel-loader is not run on the import because it complains about parsing errors. So my setup is a in the packages dir there is a dir called in my app I have an import
so the import is resolved successfully, but the babel-loader isn't run it seems. Is this expected behaviour? |
This doesnt seem to be true. I have just created a fresh react app and am getting these same errors. NODE_PATH is not set on my system, and putting it in .env does not resolve absolute imports. |
Any solution about this? |
EDIT: With more investigation my issue seems to be reserved to the typescript version of CRA 2.x. I can get non typescript version working and it seems most of my error are being reported by the ts compiler. To get the typescript version working I'm sure it's just another setting I'm missing in my tsconfig. |
If you're still looking for a solution, have a look at #5118 (comment) |
@unzico your solution suggest using typescript + other libraries which was not the intend of reporting this issue! |
It’s sad that the maintainers decided to close this issue instead of offering a solution |
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: facebook/create-react-app#476 facebook/create-react-app#693 facebook/create-react-app#741
According to the links below I understand .env with
NODE_PATH=src
in it, allows the react app to take advantage of Absolute Path Imports without ejecting.so far I've managed to load REACT_APP_TEST_VAR in my process.env which indicates the file is being loaded ! but i cant import anything from src
or src/components folder
So far I've tried moving the NODE_PATH into .env && .env.development restarting node and webpack, rebooting the system
create-react-app/packages/react-scripts/config/env.js
Line 61 in 25184c4
Environment
Environment:
OS: Linux 4.15
Node: 9.10.0
Yarn: 1.7.0
npm: 6.4.0
Watchman: Not Found
Xcode: N/A
Android Studio: Not Found
Packages: (wanted => installed)
react: ^16.4.2 => 16.4.2
react-dom: ^16.4.2 => 16.4.2
react-scripts: ^1.1.5 => 1.1.5
Steps to Reproduce
The text was updated successfully, but these errors were encountered: